< YALU STUDIO >

C# .NET Notes

Word count: 233 / Reading time: 1 min
2020/03/01 Share

Code snippet shortcut

Press tab twice to use code snippets

cw -> Console.WriteLine();

props

String Format

  1. C or c -> Currency

Console.WriteLine("{0:c}", 99999);

> $99,999.00

  1. D or d -> Decimal numbers with padding

Console.WriteLine({0:d9}, 99999);

> 000099999

  1. F or f -> Fixed-point with padding

Console.WriteLine({0:f3}, 99999);

> 99999.000

  1. N or n -> Basic numerical formatting (with commas)

Console.WriteLine({0:n}, 99999);

> 99,999.00

  1. E or e -> Exponential notation

Console.WriteLine({0:E}, 99999);

> 9.999900E+004

Console.WriteLine({0:e}, 99999);

> 9.999900e+004

  1. X or x -> Hexadecimal

Console.WriteLine({0:X}, 99999);

> 1869F

Console.WriteLine({0:x}, 99999);

> 1869f

  1. G or g

Verbatim Strings

Prefix a string with@, you can have the string as it is.

1
Console.WriteLine(@"C:\MyApp\bin\Debug")

Datetime

DateTime dt = new DateTime(1995, 2, 2);

Conditions

Switch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
switch(choice)
{
case int i when i == 2:
case string s when s.Equals("VB", StringComparison.OrdinalIgnoreCase):
Console.WriteLine("VB: OOP, multithreading, and more!");
break;
case int i when i == 1:
case string s when s.Equals("C#", StringComparison.OrdinalIgnoreCase):
Console.WriteLine("Good choice, C# is a fine language.");
break;
default:
Console.WriteLine("Well...good luck with that!");
break;
}

Interface

as returns reference or null

is returns true or false

CATALOG
  1. 1. Code snippet shortcut
  2. 2. String Format
    1. 2.0.1. Verbatim Strings
  • 3. Datetime
    1. 3.1. Conditions
    2. 3.2. Interface