C# Note

Note for C# programming language

C# Note

1 Hello World

1.1 Demo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
/// <summary>
/// document comment
/// </summary>
class Program
{
static void Main(string[] args)
{
/*
* block comment(multiline)
*/
Console.WriteLine("Hello World!"); // line comment(single line)
}
}
}

1.2 Notes

  • main function is written as static void Main(string[] args)
    • Main starts with Capitalized character
  • To print text in console screen, use:
    • Auto end with new line: Console.WriteLine(...)
    • no auto ending new line: Console.Write(...)
  • Comment has 3 types:
    • document comment: /// ...
      • Attention: this should be only written in front of class/method/attribute.
    • block comment: /* ... */
    • line comment: // ...
  • type cast:
    • lower precision variable can be converted to higher precision automatically, however, higher precision variable has to be cast to lower precision manually by code.
    • c# double d = 2.5; int x = (int)d + 1; // cause ERROR if no (int) cast