Welcome to the C# Guide


Programming Languages

Latest in Tech

Zettonia Education

C# Quickstart

C# is a language geared towards Microsoft Systems such as .NET application framework, Xamarin cross-platform app development, and Unity to develop games on the Unity development platform, which runs on C#

Download C# from Visual Studio. You can use the free Visual Studio Community.

Follow the link below to download Visual Studio.

Download VisualStudio

The C# Syntax && Ecosystem

Jump to:

Data Types  Variables  Conditional Statements  Loops  Functions  NuGet 

C# Basics

Data Types

C# datatypes pays more attention to the memory length, similar to C++.

  • Integers : Whole numbers (Signed/unsigned)
  • Float : Numbers with decimals(single precision)
  • Double : Numbers with decimals(double precision)
  • String : Text
  • Boolean : True or False
Data Structures
  • Lists

Output to console

Console.WriteLine("Hello World");

Comments

// Single-line comments are denoted with the two slashed //. This line will be ignored by the C# compiler.
/*
Multi-line comments
are denoted by /* and */
*/

Variables

Declaring constants: It's kinda like Algebra

int my_var,  my_var2;
double d1, d2;
Console.WriteLine( my_var , my_var2, d1, d2);

Variables with math operations: Here comes to Algebra

double d1, d2;

d1 = 3.21;
d2 = 9.1235;
Console.WriteLine( d1, d2);

Variables with Arrays

int[] myarray = new int[] { 10, 20, 30, 40 };

If Else Conditional Statements:

Comparison Operators Meaning
== Is equal to
> More than
< Less than
>= More than or equal to
<= Less than or equal to
!= Not Equal to
Boolean Operators Meaning
&& and
|| or
! not
If, Else If, Else:

bool condition = True:

if (condition) {
    Console.WriteLine("Actions if True")
}

else {
    Console.WiteLine("Actions if False")
}

Switch Case:
IDictionary my_cat = new Dictionary(){
   "name":"Mr. Fluffy",
   "age":20,
};
switch (my_cat["name"]){
case "Mr.Fluffy":
     Console.WriteLine("hello mr fluffy");
     break;
case "Mr.Pinky":
     Console.WriteLine("hello mr pinky");
     break;
// There may be more cases to add
default:
     Console.WriteLine("Default case");
     break;
/* break will break you out of this switch/case
and will continue with the next block of code
*/
}

Loops: do something over a range or while something is true

// Try these codes out
for ( i=0 ;<10 ; i++){
     Console.WriteLine(i);
}

int[] my_array = [10,20,30];
for ( int i in my_array){
     Console.WriteLine(i);
}

// Try these codes out
bool hungry = True;
while (hungry == True){
     Console.WriteLine("I will have some pizza.")
     Console.WriteLine("Eating...")
     Console.WriteLine("Done eating. Not hungry any more!")
     hungry = False
     // when we change hungry to False, we will exit the while loops
     // we can use break here too, to break out of the while loop
{
Console.WriteLine("We are out of the while loop...")

Functions: Reusable blocks of codes

public str AreYouHungry(bool a, str b){
     // a is the parsed data. we can use "a" within this function. We will parse True or False
     if (a == False){
          return "Go Home";
     } else if (hungry == True and b =="pizza"){
          return "Go to Pizza Restaurant";
     } else{
          return "Find some other restaurant";
     }
}
// Calling the function with hugry,food_type
str result = are_you_hungry(True,"pizza");
Console.WriteLine(result);


Nuget

Nuget is a package manager for .NET.
You can use it to install libraries/dependencies like Express.

Ready to dig deeper into C#?

Zettonia Education Programmes