var b = 12345;
Console.WriteLine(b.GetType().FullName);
byte c = 212;
unsafe {
byte* pc = &c;
Console.WriteLine(((IntPtr)pc).ToString("X"));
Console.WriteLine(*pc);
}
Console.WriteLine($"{nameof(b)}的值为{b}");
Console.WriteLine($"{nameof(c)}的值为{c}");
unsafe {
byte* pc = &c;
Console.WriteLine($"{nameof(pc)}的值为{*pc}");
}
int v = 0;
int v2 = default(int);
Console.WriteLine($"int的默认值为{v2}");
string s = default(string);
Console.WriteLine($"string的默认值为{s}");
Console.WriteLine($"string的默认值为{s??"null"}");
string s2 = default;
Console.WriteLine($"string的默认值为{s2 ?? "null"}");
foreach (var str in args) {
Console.Write(str + " ");
}
string input = Console.ReadLine();
if (!uint.TryParse(input, out uint number) || number < 0) {
Console.WriteLine("输入无效");
}
if (number % 2 == 1)
{
Console.WriteLine("奇数");
}
else {
Console.WriteLine("偶数");
}
List<string> strings = new List<string>();
string sss = "";
for (int i = 0; i < 5; i++) {
sss += "*";
var temp = sss;
strings.Add(temp);
Console.WriteLine(temp);
}
List<string> strings2 = new List<string>();
foreach (var ss in strings) {
var temp2 = ss.PadRight(8);
var temp3 = ss.PadLeft(8);
strings2.Add(temp2+temp3);
Console.WriteLine(temp2+temp3);
}
strings2.Reverse();
foreach (var ss in strings2)
{
Console.WriteLine(ss);
}
while (true) {
Console.WriteLine("请按Esc退出");
if (Console.ReadKey(true).Key == ConsoleKey.Escape) {
break;
}
}
object vx = 123456f;
switch (vx) {
case string t: Console.WriteLine($"这是字符串{vx}"); break;
case double d: Console.WriteLine($"这是double{vx}"); break;
case float f: Console.WriteLine($"这是float{vx}");break;
}
vx = "";
switch (vx)
{
case string t when t.Length==0: Console.WriteLine($"空字符串"); break;
case double d: Console.WriteLine($"这是double{vx}"); break;
case float f: Console.WriteLine($"这是float{vx}"); break;
}