C# video study notes (1)

1. Variable declaration and initialization

	Int number=10;

2. Display

	Console.WriteLine("One Two Three Four Five");
	Console.ReadKey();

3. Get user input

	String fruits=Console.ReadLine();

4. Escape character

        \+ special symbol --- display symbol

        \n---Enter

        \t---align display

        \b---The cursor position moves forward one

 

5. Implicit and explicit conversions

	//int to double
	int num1 = 90;
	double num2 = num1;
	Console.WriteLine(num2);
	Console.ReadKey();
	
	//double to int
	double num1 = 22.2;
	int num2 = (int) num1;
	Console.WriteLine(num2);
	Console.ReadKey();

	//Convert.To type (original data);
	int chinese = Convert.ToInt32(strChinese);


6. The way to convert strings to numbers

	//one
	Console.WriteLine("Please enter a number");
	string strNum=Console.ReadLine();
	int age = Convert.ToInt32(strNum );//If the input content is not a number, an exception will occur
	
	//two
	Console.WriteLine("Enter numbers");
	string strNum = Console.ReadLine();
	int age = int.Parse(strNum);
	//double douNum=double.parse
	
	//three
      Console.WriteLine("Enter numbers");
      string strNum = Console.ReadLine();
      int age;

      bool result = int.TryParse(strNum, out age)

7. Enumeration

	Public enum MyEnum
	{
		male,
		Female
	}


8. Structure

	Public struct MyStruct
	{
		public string _name;// field
		public int _age;
		public Gender _gender;
	
	}


9. Arrays

   

Declare multiple variables of different types at once - struct

Declare multiple variables of the same type at once - an array

	//Declaration of the array:
		int[] numbers = new int[] { 1,2,3};
		int[] nums = new int[10]
		int[] num3=new int[3] {1,2,3}
		int[] nums={1,2,3,4,5};
		
	//The value of the array:
		int[] nums = new int[10];
		nums[5] = 23;
		nums[7] = 100;
		Console.WriteLine(nums[5]);
		Console.WriteLine(nums[7]);
		Console.ReadKey();


(To be continued...)


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325917460&siteId=291194637