Basics

The parentheses are known as the method invocation operator.

Datatypes/Literals

  • string - for words, phrases, or any alphanumeric data enclosed by double-quotes.

  • char - for a single alphanumeric character enclosed by single quotes.

  • int - for a numeric whole number.

  • decimal - for a number with decimal values and m/M as a literal suffix.

  • bool - for a true/false boolean values.

Console.WriteLine("Hello, World!");    //string

Console.WriteLine('a');                //char

Console.WriteLine(123);                //int

Console.WriteLine(123.456m);            //decimal
Console.WriteLine(123.456M);                    

Console.WriteLine(true);                //bool
Console.WriteLine(false);

Note

string and char are only used for presentation, not for calculation.

Variables

  • Variables are temporary values you store in the computer's memory.

  • Before you can use a variable, you have to declare it.

  • To declare a variable, you first select a data type for the kind of data you want to store and then give the variable a name that follows the rules.

bool processedCustomer;
char userOption;
decimal particlesPerMillion;
int gameScore;
string firstName;
  • You must assign (set) a value to a variable before you can retrieve (get) a value from a variable.

  • You can initialize a variable by assigning a value to the variable at the point of declaration.

  • Assignment happens from right to left.

  • You use a single equals character as the assignment operator.

An implicitly typed local variable is created using the var keyword. The var keyword tells the compiler to infer the data type of the variable based on the value it is initialized to.

var message = "Hello world!";

Note

You can only use the var keyword if the variable is initialized.

An string/character escape sequence is a special instruction to the runtime that you want to insert a special character that will affect the output of your string.

  • \u - add encoded characters in literal strings, then a four-character code representing some character in Unicode (UTF-16).

Console.WriteLine("\u3053\u3093\u306B\u3061\u306F World!");

Output: ใ“ใ‚“ใซใกใฏ World!

By default, all class members are sealed and cannot be overridden. To override we must expose it by using abstract or virtual keyword.

Last updated