C# Programming Notes


Home

BCL – Base Class Library
SDK – Software Development Kit
IDE – Integrated Development Environment
Using Visual Studio IDE visual studio community edition

https://visualstudio.microsoft.com/downloads

C#, Linux, macOS, Windows, Console – Console Application – this is the needed template.
Console.WriteLine(“Hello World!”); //string literal
Console and WriteLine are called identifiers
The period between the two is called a member access operator or dot operator.
Name binding – What the code refers to.
Console is the class and WriteLine is the method.
Method invocation or method call – act of asking a method to run
System.Console.WriteLine(“Hello, world!”);
using System; // in older C#, not needed now
Variables are containers for data.
string name;
name = “User”;
Console.WriteLine(“Hi “ + name);
string name;
Console.WriteLine(“What is your name?”);
name = Console.ReadLine();
Console.WriteLine(“Hi “ + name);
Debug and Release configurations
Use Debug when working on program, release when sharing with others.
// for comment /* and */ for section comments
3 parts of a variable – name, type, and contents.
Declare, assign, retrieve.
score = 0; // 0 is an int literal
= means assignment, not equality
int x = 0; // declare and initialize on same line
int a, b, c; // declare multiple variales simultaneously
a = b = c = 10; // assigned same value to several variables
Console.WriteLine(42); // Writes integer to screen.
No numbers or special characters at start of variable names.
Use letter or _ to start them.
Can not use int or string in variable name, or a – symbol.
Don't end with numbers.
Avoid vague names
Use camel's hump in several name variables.
8 integer types – int, short, long, byte, sbyte, uint, ushort, ulong
bool – true and false
Convert to change types
aVeryBigNumber = 100000000000UL;
1,000,000,000
int bigNumber = 1_000_000_000;
Use mainly int, uint, long or ulong.
char aLetter = 'a'
\u before hexadecimal code
string message = “Place message in here.”
3 types of floating point numbers – float, double, and decimal
double avogadrosNumber = 6.022e23;
bool itWorked = true;
itWorked = false;
char aLetter = 'a';
string message = 'Hello, world.';
int favoriteNumber = Convert.ToInt32(favoriteNumber);
int number = int.Parse("9000");

+, -, *, /, %
multiply and divide before addition and subtraction
+=. -=. *=. /=, %=
Math and MathF
casting x=(int)3.3

int a = 1;
int b = a + 4;
int c = a-b;

computes remainders
int remainder = n % 2; // It this is an even number, then 'n' is an even number