Some understanding of c# simple data types

first understand

  1. declare variables

  • Declaring a variable is to specify the name and type of the variable. The declaration of the variable is very important. The undeclared variable itself is illegal and cannot be used in the program.

  1. Variable Naming Rules

  • Variables can only consist of numbers, letters, and underscores

  • The first character of the variable name can only be letters and underscores, not numbers

  • Cannot use c# keywords as variable names


integer type

type name

  1. sbyte: 8-bit signed integer

  1. short: 16-bit signed integer

  1. int: 32-bit signed integer

  1. long: 64-bit signed integer

  1. byte

  1. ushort

  1. uint

  1. head

practise

int number=1;
Console.WriteLine(number);

floating point type

type name

  1. float: 32 bits, precision 7 bits

  1. double: 64 bits, precision 15

  1. decimal: 128 bits, precision 28 bits

practise

double number=1.1;

tips

If no setting is made, the value containing the decimal point is double by default, if it is to be converted to float (f), double (d), decimal (m)

decimal s=1.12m;

Boolean type

bool

bool flag=true;

character type

type name

  1. Char

  1. string

escape character

  1. \n: carriage return line feed

  1. \":Double quotes

  1. \b: backspace

  1. \r: carriage return

  1. \f: Form feed

practise

string a="c#是世界上最好的语言";

variable scope

Member variables

  1. static variable

For static variables, in addition to being used in the class that defines it, you can also use "class name. static variable" in other classes

static int a=100;
  1. instance variable

int a=100;

local variable

Variables defined between braces are called local variables


little practice

 Console.WriteLine("输入字符串");
            string number = Console.ReadLine();
            Console.WriteLine("字符串为"+number);
            Console.ReadLine();

 int a = 10;
            int b = 20;
            int temp=a;
            a=b;
            b = temp;
            Console.WriteLine("a的值{0},b的值{1}", a, b);
            Console.ReadLine();

Guess you like

Origin blog.csdn.net/weixin_51983027/article/details/129272260