Skip to content
Jasper Zanjani edited this page Aug 16, 2020 · 8 revisions

C#

TOLEARN:

var btn = new Button
{
  Margin = new Thickness(10, 20, 10, 30);
};

Hello World program illustrating the basic structural template

using System;

namespace HelloWorld 
{
  class Program 
  {
    public static void Main() 
    {
      Console.WriteLine('Hello World!'); 
    }
  }
}

Abstracting a function and calling it Miles

using System;

namespace HelloWorld 
{
  class Program 
  {
    static void doit () 
    {
      Console.WriteLine ("Hello"); 
    }
    public static void Main () 
    {
      doit();
      doit(); 
    } 
  } 
}

Strings

Formatted strings

string word1 = "dreary";
string word2 = "weary";

Console.WriteLine($"Once upon a midnight {0}," word1);
Console.WriteLine($"While I pondered weak and {word2}");

Generics

Generics make it possible to define strongly-typed collections

var list = new List<int>();
list.Add(1);
list.Add(2);
list.Add("three"); // error
Clone this wiki locally