C# 基础
2020-12-13 15:12
标签:style blog io color ar os sp div on 1.枚举 2.数组:必须同类型 3.命名空间-别名 4.Console.Write() 5.C#变成规则 Pascal大小写形式:命名空间,类以及基类中成员等。如EmployeeSalary; camel大小写形式: C# 基础 标签:style blog io color ar os sp div on 原文地址:http://www.cnblogs.com/ddctz/p/4072352.html 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace Test
8 {
9 public enum TimeOfDay
10 {
11 Morning = 0,
12 Afternoon = 1,
13 Evening = 2
14 }
15 class Program
16 {
17 static void Main(string[] args)
18 {
19 TimeOfDay time = TimeOfDay.Afternoon;
20 Console.WriteLine(time.ToString()); //输出:Afternoon
21
22 TimeOfDay time2 = (TimeOfDay)Enum.Parse(typeof(TimeOfDay), "afternoon", true);
23 Console.WriteLine((int)time2);
24 }
25 }
26 }
27 //Enum.Parse(枚举类型,需转换的字符串,bool(是否忽略大小写)),返回对象(此处TimeOfDay.Afternoon),需显示转换。
1 int[] arrays = new int[32];
2 Console.WriteLine(arrays.Length);//返回数组长度
3
4 int[] arrays2;
5 Console.WriteLine(arrays2.Length);//报错
1 using System;
2 using Introduction = Wrox.ProCSharp.Basics;
3
4 //...
5
6 Introduction::NamespaceExample NSEx = new Introduction::NamespaceExample(); //命名空间别名修饰符::
1 int i = 730;
2 int j = 73;
3 Console.WriteLine("{0,4}\n+{1,4}\n----\n{2,4}", i, j, i + j);
4 decimal m = 940.23m;
5 decimal n = 73.7m;
6 Console.WriteLine("{0,9:C2}\n+{1,9:C2}\n------\n{2,9:C2}", m, n, m + n);
7 //{x,y:z} x表示参数索引,y表示宽度值(正值右对齐,负值左对齐),z表示格式字符串,如C2表示精度到小数点后两位或者{x,y:#.00}
1 //类中所有私有成员字段的名称
2 public int subscriberId;
3
4 //成员字段通常下划线开始
5 public int _subscriberId;
6
7 //传递的形参数
8 public void RecordSale(string salemanName, int quantity);
上一篇:二、python介绍
下一篇:C#基础---事件的使用