C# Basic
YXYDouble
这个作者很懒,什么都没留下…
展开
-
Nullable Operators (C#)
Null-Coalescing Operator (??) It is a shorthand to check if the variable is null before accessing its value.int? i = null;string? temp="I'm not null!";int index = i ?? 0;string result = temp ?? "Null";Console.WriteLine(index);Console.WriteLin..原创 2022-05-03 18:07:55 · 87 阅读 · 0 评论 -
Nullable Types (?) (C#)
Nullable Value Type The ? suffix is a shorthand for creating an instance of the generic System.Nullable<T> structure.static void NullableItems(){ int? item1 = 0; // Nullable<int> item1 = 0; bool? item2 = null; // Nullabl..原创 2022-05-03 17:49:41 · 218 阅读 · 0 评论 -
Value Types and Reference Types (C#)
C# structs are derived from System.ValueType which overrides the virtual methods in System.Object to use value-based semanitcs instead of reference-based ones.System.ValueType is allocated on stack rather than on garbage-collected heap. Its lifetime is i原创 2022-05-03 16:33:42 · 72 阅读 · 0 评论 -
enum (C#)
Default storage type of enum is System.Int32.The storage type could be changed to byte, short, int and long,var vehicle1 = VehiclesTypeEnum.MiniVan;Console.WriteLine($"The result is " + $"{Enum.GetUnderlyingType(vehicle1.GetType())}");Console.W原创 2022-05-03 14:59:35 · 192 阅读 · 0 评论 -
Method Parameter Modifiers (C#)
Modifier Remarks (None) value type: passed by value (a copy of data) reference type: passed by reference out out parameters are passed by reference. Must be assigned in the method. in to indicates that the ref parameters are r原创 2022-05-03 10:03:16 · 116 阅读 · 0 评论 -
switch (C#)
switch on an enumeration data type; static void SwitchOnEnum() { Console.WriteLine("Enter your favorite day of the week: "); DayOfWeek day; try { day=(DayOfWeek) Enum.Parse(t.原创 2022-05-02 17:36:17 · 720 阅读 · 0 评论 -
Tuple (C#)
C# Tuple原创 2022-04-12 10:14:53 · 149 阅读 · 0 评论 -
struct (C#)
C#, structure, struct原创 2022-04-12 16:14:39 · 256 阅读 · 0 评论 -
Pattern Matching (C#)
if/else Pattern Matching (C# 7.0)Use "is" keyword to check the type of an objectExample: static void FindPattern() { object item1 = 10; object item2 = "Hello!"; if(item1 is int value1) {原创 2022-05-02 15:37:34 · 268 阅读 · 0 评论 -
Conditional Operator (?:) (C#)
condition ? expression1 : expression2;When condition is true, expression1 is executed.Experssion2 is executed when false.It is used only in assignment statement.Expression1 and experssion2 must have implicit conversions from one to another.It can .原创 2022-05-02 16:06:48 · 390 阅读 · 0 评论