随便记点

刚学

C#10.0

引用空间在解决方案里,单击打开代码编辑或查看。也可以右键解决方案-属性里编辑。

命名要规范,double类型不要拿来做==的对比,目前有个疑问。

C#的格式化字符串不太能理解,还有

Console.WriteLine(format:"{0,-10} {1,6:NO}",arg0:"Name",arg1:"Count");

Console.WriteLine("{0,-10} {1,6:NO}",  "Name",  "Count");

这俩差别在哪?

看完第二章了,练习2.3:

 

 自己写的:

using static System.Console;
string[] a = new[]{"sbyte","byte","short","ushort","int","uint","long","ulong","float","double","decimal"};
WriteLine("------------------------------------------------------------------------");
WriteLine("{0,-8}{1,-17}{2,17}{3,30}","Type","Byte(s) of memory","min","Max");
WriteLine("------------------------------------------------------------------------");
WriteLine($"{a[0],-8}{sizeof(sbyte),-4}{sbyte.MinValue,30}{sbyte.MaxValue,30}");
WriteLine($"{a[1],-8}{sizeof(byte),-4}{byte.MinValue, 30}{ byte.MaxValue,30}");
WriteLine($"{a[2],-8}{sizeof(short),-4}{short.MinValue,30}{short.MaxValue,30}");
WriteLine($"{a[3],-8}{sizeof(ushort),-4}{short.MinValue,30}{short.MaxValue,30}");
WriteLine($"{a[4],-8}{sizeof(int),-4}{int.MinValue,30}{int.MaxValue,30}");
WriteLine($"{a[5],-8}{sizeof(uint),-4}{uint.MinValue,30}{uint.MaxValue,30}");
WriteLine($"{a[6],-8}{sizeof(long),-4}{long.MinValue,30}{long.MaxValue,30}");
WriteLine($"{a[7],-8}{sizeof(ulong),-4}{ulong.MinValue,30}{ulong.MaxValue,30}");
WriteLine($"{a[8],-8}{sizeof(float),-4}{float.MinValue,30}{float.MaxValue,30}");
WriteLine($"{a[9],-8}{sizeof(double),-4}{double.MinValue,30}{double.MaxValue,30}");
WriteLine($"{a[10],-8}{sizeof(decimal),-4}{decimal.MinValue,30}{decimal.MaxValue,30}");
WriteLine("------------------------------------------------------------------------");

运行:

 

 

 

 看了眼mark的代码:
using static System.Console;

WriteLine("--------------------------------------------------------------------------");
WriteLine("Type    Byte(s) of memory               Min                            Max");
WriteLine("--------------------------------------------------------------------------");
WriteLine($"sbyte   {sizeof(sbyte),-4} {sbyte.MinValue,30} {sbyte.MaxValue,30}");
WriteLine($"byte    {sizeof(byte),-4} {byte.MinValue,30} {byte.MaxValue,30}");
WriteLine($"short   {sizeof(short),-4} {short.MinValue,30} {short.MaxValue,30}");
WriteLine($"ushort  {sizeof(ushort),-4} {ushort.MinValue,30} {ushort.MaxValue,30}");
WriteLine($"int     {sizeof(int),-4} {int.MinValue,30} {int.MaxValue,30}");
WriteLine($"uint    {sizeof(uint),-4} {uint.MinValue,30} {uint.MaxValue,30}");
WriteLine($"long    {sizeof(long),-4} {long.MinValue,30} {long.MaxValue,30}");
WriteLine($"ulong   {sizeof(ulong),-4} {ulong.MinValue,30} {ulong.MaxValue,30}");
WriteLine($"float   {sizeof(float),-4} {float.MinValue,30} {float.MaxValue,30}");
WriteLine($"double  {sizeof(double),-4} {double.MinValue,30} {double.MaxValue,30}");
WriteLine($"decimal {sizeof(decimal),-4} {decimal.MinValue,30} {decimal.MaxValue,30}");
WriteLine("--------------------------------------------------------------------------");

.....字符串能直接塞里面去啊,尬了

睡了睡了,今天就到这

posted @ 2022-11-24 03:37  14053737  阅读(26)  评论(0编辑  收藏  举报