2. How to be a Programmer
Essentials:
• A Computer
• An OS
• An IDE
• You.
Requisites:
• Visual Studios 2015 or below.
• A problem solving brain
• Music or other ambience cancelling approaches
• An Internet connection
Pre-Requisites
Past programming experience
3. C# is…..
• A programming language with multiple paradigms .
• A high level language.
• A simple, modern, general-purpose, portable and robust language.
• A pretty cool tool to use.
5. Your first Program
Hello World
using System;
using System.Collections.Generic;
namespace ConsoleApplication1
{
class FirstProgram
{
static void Main(string[] args)
{
string intro = "Hello ZUdin!!";
Console.WriteLine(intro);
Console.ReadKey();
}
}
}
There is a history why this is made to be the first program!
• using – Implementing another namespace into
your created namespace.
• namespace – a collection of classes.
• class - A collection of methods and expressions.
• Main – The function which acts as the entry point
for the program.
6. Data Types
These are the basic blocks which you will operate on
to create results.
The following are a few data types:
1. Integer
2. Float
3. Decimal
4. Long
5. Short
6. Byte
7. Char
8. String
9. Boolean
Advanced
10. Arrays
11. Dictionary
12. List
13. Object
14. Dynamic
15. Pointer
16. Null
Numerical – int, float, decimal, long, short, byte
Alphanumerial – char, string
Boolean – Boolean
Advanced –
i. Arrays – Either Numerical, Alphabetic or
Boolean.
ii. Dictionary – Either Numerical, Alpha or
Boolean
iii. List – Either Numeric, Alphabetic or Boolean.
iv. Object – Base type for all data types.
v. Dynamic – Any type. Bypassing the static field
vi. Pointer – Points at a reference object.
7. Operators
Perform operations on variables.
• Every function or method is a custom
operation.
• Basic mathematical operations
• + : Addition
• - : Subtraction
• / : Division
• * : Multiplication
• == : Equality
• != : Inequality
• <= : Greater than and equal to
• >= : Lesser than and equal to
• += : Add variable to self
• -= : Subtract variable from self
• ++ : Add 1 to self
• -- : Subtract 1 from self
• ! : NOT
• && : AND
• || : OR
• Advanced Operations
• Math.<Insert function name here>
• Other in-built functions
• Custom Functions
8. The little essentials
Comments:
Use them often for your future self’s sanity + others.
// This is for single line comments
/* We are
*Legion
* And we are a single unit.
This is a multi line comment*/
White Space:
This shows the user and the computer (sometimes) that
this part of the program is another function or method.
Whitespace can be created by the Tab key or 4
Spaces.
Whitespace methods modify space and
newline characters. Advanced uses for File
I/O might be taught in the course.
The curly bracket:
Used to define sections of the code.
Strongly coded language.
Each function, class and namespace has to be
followed by an opening and closing curly
bracket.
The semicolon:
Used to differentiate between lines of code.
Strongly coded syntax.
9. Functions: Ins and Outs
Functions are basically your custom operations within a class. Thus these operations can have inputted values in them
and they can output values to the calling method or statement.
private object SendAndReturn(int[] numbers, int num, etc.)
{
return objectvariable;
}
Data Type of the variable
which is returned via the
return statement in the
method/function.
Return Statement
followed by a
variable which has
type object.
Variables which are feeded into the
function/method. Can be as many as
possible. The data type is stated for
each variable in the function instance.
When calling, only the variable name is
written.
10. Functions
The MAIN function:
• This is the GOTO function for the compiler.
• The program starts and ends on this function.
• All other methods are sub-routines for this function.
• This function should be as small as possible for ease of debugging.
Custom functions:
• Called by the MAIN function.
• Values can be passed onto them and can be returned from them. (Single or multiple)
• Variables inside methods cannot be used outside them. They are only present when the method is called and
deleted when it ends.
• Can call other functions but cannot call on the MAIN function.
12. Static
A static function, unlike a regular (instance) function, is not associated with an instance of the class.
A static class is a class which can only contain static members, and therefore cannot be instantiated.
For example:
class SomeClass {
public int InstanceMethod() { return 1; }
public static int StaticMethod() { return 42; }
}
In order to call InstanceMethod, you need an instance of the class:
SomeClass instance = new SomeClass();
instance.InstanceMethod(); //Fine
instance.StaticMethod(); //Won't compile
SomeClass.InstanceMethod(); //Won't compile
SomeClass.StaticMethod(); //Fine
14. Iterating Codes
Writing the same code again and again is bad practice and is looked down on.
This is due to the following reasons:
1. Extra Lines of code makes it harder to navigate the code.
2. More Lines, More Errors.
3. Harder to understand .
4. Alternative are better.
Functions:
1. For Loop
2. For Each
3. While Loop
4. Do While
5. If Else Statement
6. Switch Statement
15. For this till here, do that.
for (int count = 0; count < 100; count++)
{
<Insert your Code here>
}
A normal incrementing for loop
There are several types of for loop variations.
These are some of them:
1. Incrementing
2. Decrement
3. Increment, step
4. Decrement, step
5. Function
6. Char
Looping inside a loop inside a loop and on and on. You can
have nigh endless amounts of them but what are you going
to use them for??
A normal 3 loop example would be going through all the
cells of a 3D array. Visualizing a 3D object would be easy
but what would happen when you start thinking about a 4D
object or more.
16. For Loops
for (int count = 0; count < 100; count++)
{
<Insert your Code here>
}
There are 3 statements in the for loop function which makes it
unique.
1. The first one initializes a variable or uses a variable or your
making. Here we initialize a variable called count which is
an int type with the value of 0
2. The second statement gives the compiler a condition where
the loop would end. Over here, we want it to run till the
point where it has reached 100 and it stops at 100.
3. The third statement tells the compiler that the variable
count will increase its value by 1 every step.
A FOR loop has certain condition where it has its
advantages and disadvantages. These are some:
1. All loops work with strings and char type but
a FOR loop is preferred for its syntax and
index variable.
2. It is often the fastest way to loop over large
sets of numbers. It is easy for the compiler to
optimize.
3. Nesting loops inside is confusing.
4. Optimization requires quite a lot of
brainstorming because faster methods are
not as simple as using a for loop.