C # overview notes (2021-1223)

Posted by mastermike707 on Thu, 30 Dec 2021 13:33:13 +0100

C #'s five data types:

1) Class (such as Windows,Form,Console,String,etc.);

2) Structures (such as int32,int64,Single,Double,etc.);

3) Enumeration (such as horizontal, alignment, visibility, etc.);

4) interfaces;

5) Delegates;

C# - function keys:

1. Tools – > Options - > text editor – > all languages – > General – > line number;

2. Tools – > Options - > environment – > font and color – > font (Consolas);

3. Solution – > properties – > current selection (when executing multiple solutions);

C# - Syntax:

1,match_ area_ img_ out = match_ area_ img_ 1.Convert<Gray, Byte>();// (convert match_area_img_1 into grayscale image); (convert the image defined by image into grayscale image through convert);

2,int count1 = Convert. ToInt32(textBox1.Text); // Convert string type to int type, and use textbox to automatically resize;

3, displab1.Text = "area:" + area ToString(); // Print letter matching information;

4, double num1 = Convert.ToDouble(textBox2.Text);// Realize the conversion from string type to double type;

5. Before using a variable, you need to define the variable type and variable name;

6, myString = “\“myInteger\” is”;// (\ n newline character; \ "escape character; \ \ escape character);

7,Console.WriteLine("{0} {1}.", myString, myInteger);//{0} {1} placeholder;

8. The first character of a variable name must be a letter, an underscore Or @; The following letters can be numbers, letters and underscores;

9. PascalCase naming: the first letter is uppercase and the rest is lowercase (PascalCase naming method is usually used for namespace namespace elimination); camelCase naming: the first word is lowercase and the rest is uppercase;

10,int myInteger;//camel variable naming (the first word is lowercase and the first letter of subsequent words is uppercase); string myString;//camel variable naming (the first word is lowercase and the first letter of subsequent words is uppercase);

11,int age,height,weight; (define multiple variables of the same type at the same time);

12, int age=18,height=175,weight=60; (define multiple variables of the same type and assign values at the same time);

13, match_ area_ img_ 1 = match_ area_ img. AbsDiff(temp);// (1220 add, temp \ match_area_img absolute value difference, image difference absolute value);

C# - shortcut keys:

1. Ctrl+k+c: batch comment code (/,,, / multi line comment; / / comment content; / / / text comment / /); Ctrl+k+u: batch uncomment code;

2. F5: debugging operation, Ctrl+F5: non debugging operation; F10, gradual process; F11, sentence by sentence;

3. Ctrl+Shift+N: new project;

4. #region, #endregion (added at the beginning and end of the code to collapse and expand the code);

5. Select a few lines of code, and then use tab (move left as a whole) or shift + Tab (move right as a whole);

## C#Hello World
## ##console(Console Application )##

Console.WriteLine("Hello World");

Console.ReadKey();

establish. NET application steps:

C# code ----- > compile as (CIL) - > store in assembly ----- > compile the code into native code through JIT compiler.

C# applications:

1) Console application;

2) Windows Forms application (WinForm); (graphical interface can be designed)

C# -Console logical operator:

//Relational and logical operators;
Console.WriteLine("Hello C# World!");//Print Hello C# World!;
Console.ReadKey();
Console.WriteLine("Please enter your language score:");
//string str_chinese = Console.ReadLine();
//int chinese = Convert.ToInt32(str_chinese);// String str_ Convert Chinese to integer Chinese ;
double chinese = Convert.ToDouble(Console.ReadLine());//The result is the same as the two lines of code;
//double chinese = Convert.ToDouble(str_chinese);// String str_ Convert Chinese to double precision floating-point chinese(double);
Console.WriteLine("Please enter your math score:");
string str_math = Console.ReadLine();
//int math = Convert.ToInt32(str_math);// String str_ Math is converted to integer math ;
double math = Convert.ToDouble(str_math);//String str_math is converted to double precision floating-point math(double);
Console.WriteLine("Please enter your English score:");
string str_english = Console.ReadLine();
//int english = Convert.ToInt32(str_english);// String str_ Convert English to integer English ;
double english  = Convert.ToDouble(str_english);//String str_english is converted to double precision floating-point english(double);
double sum = chinese + math + english;
double avg = sum / 3;
Console.WriteLine("What is your total score in three major subjects{0},The average score is{1}",sum,avg);
Console.ReadKey();
bool b = chinese > 90 && math > 90 && english > 90;//Logical and (bool type); / / logical and takes precedence over logical or;
Console.WriteLine(b);
Console.ReadKey();
bool b1 = chinese > 90 || math > 90 || english > 90;//Logical or (bool type); / / logical and takes precedence over logical or;
Console.WriteLine(b1);
Console.ReadKey();
bool b2 = chinese != 90;//Logical non (bool type);
Console.WriteLine(b2);
//add(2021-1222)
Typota Shift the overall code to the left, Ctrl+[;Overall code shift right,Ctrl+];
//add arithmetic operator (2021-1223)
double chinese, math;
string name;
Console.WriteLine("Please enter your name:");
name = Console.ReadLine();
Console.WriteLine("Hello!{0},Welcome!!!",name);
Console.WriteLine("Please enter your language score:");
chinese = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Please enter your math score:");
math = Convert.ToDouble(Console.ReadLine());
double sum = chinese + math; 
Console.WriteLine("Your total test score is:{0}",sum);
double sub =Math.Abs(chinese-math);
double avg = sum / 2;
Console.WriteLine("Your average score in Chinese and mathematics is{0}",avg);
Console.WriteLine("The difference between your Chinese and math scores is:{0}",sub);
double product = chinese * math;
Console.WriteLine("The product of your Chinese and math scores is:{0}",product);
double divide = chinese / math;
Console.WriteLine("Your Chinese score is the of your math score{0}times",divide);
double divide1= chinese % math;
Console.WriteLine("The remainder of your Chinese score in addition to your math score is{0}",divide1);
Console.ReadKey();
//add(2021-1223)
//Judge whether the year is a leap year (2021-1223);
//int year;
Console.WriteLine("Please enter the year to judge:");
int year = Convert.ToInt32(Console.ReadLine());
bool b = (year % 400) == 0 || (year % 4 == 0 && year % 100 != 0);//Logical and have priority over logical or;
Console.WriteLine(b);
//Use if esle to judge statements;
if (b == true)
{
Console.WriteLine("The year is a leap year");
}

else
{
Console.WriteLine("This year is a normal year");
}

Console.ReadKey();
//add(2021-1223)
//Write a console application that requires the user to enter four int values and display their product.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Chapter3_5
{
    class Program
    {
        static void Main(string[] args)
        {
           //Arithmetic operator;
            int a, b1, c, d;
            Console.WriteLine("Please enter 4 values:");
            a = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("a The value of is{0}", a);

            b1 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("b1 The value of is{0}",b1);

            c = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("c The value of is{0}",c);

            d = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("d The value of is{0}",d);

            double product = a * b1 * c * d; 

            Console.WriteLine("The product of all values is:{0}", product);
            Console.ReadKey();
        }
    }
}
//add(2021-1223)

Topics: C#