当前位置:网站首页>Preliminary understanding of C #

Preliminary understanding of C #

2022-06-27 07:44:00 #math. h

C# The data types of language are divided into value type and reference type .

Value types include integers 、 floating-point 、 Character 、 Boolean type 、 Enumeration type, etc ; Reference types include classes 、 Interface 、 Array 、 entrust 、 String, etc. .

 class   type 	 Value range 
sbyte	 Signed number , Occupy 1 Bytes ,-2727-1
byte	 An unsigned number , Occupy 1 Bytes ,028-1
short	 Signed number , Occupy 2 Bytes ,-215215-1
ushort	 An unsigned number , Occupy 2 Bytes ,0216-1
int	 Signed number , Occupy 4 Bytes ,-231231-1
uint	 An unsigned number , Occupy 4 Bytes ,0232-1
long	 Signed number , Occupy 8 Bytes ,-263263-1
ulong	 An unsigned number , Occupy 8 Bytes ,0264-1
 class   type 	 Value range 
float	 Single precision floating point , Occupy 4 Bytes , Keep at most 7 Decimal place 
double	 Double precision floating point , Occupy 8 Bytes , Keep at most 16 Decimal place 

 Escape character 	 Character equivalence 
\'	 Single quotation marks 
\"	 Double quotes 
\\	 The backslash 
\0	 empty 
\a	 Warning ( Produce a beep )
\b	 Backspace 
\f	 Change the page 
\n	 Line break 
\r	 enter 
\t	 Horizontal tabs 
\v	 Vertical tabs 
 Operator 	 say   bright 
+	 Add two operands 
-	 Subtract two operands 
*	 Multiply two operands 
/	 Divide two operands 
%	 Remainder two operands 

As long as one of the values in the operand is of string type ,+ The function of the operator is to connect , Instead of adding

<<	 Move left . Move the operand on the left of the operator to the left by the specified number of digits on the right of the operator , The part on the right that is vacated due to movement   repair  0
>>	 Move the sign right . Move the operand on the left of the operator to the right by the specified number of digits on the right of the operator . If it's a positive value , The part left vacant due to movement is filled  0; If it's negative , The part left vacant due to movement is filled  1
>>> 	 unsigned right shift . and  >>  They move in the same way , Just no matter positive or negative , All the parts vacated due to movement are filled  0
~	 Bitwise non . When the calculated value is  1  when , The result of operation is  0; When the calculated value is  0  when , The result of operation is  1. This operator cannot be used for Boolean . Negate a positive integer , Add... To the original number  1, Then take a negative number ; Negate negative integers , Add... To the original number  1, Then take the absolute value 
^	 Bitwise XOR . Only two different results of the operation are  1, Otherwise  0

 Insert priority here into picture description

 If you want to jump to a position specified by a label , Use it directly  goto  Just sign .

 In the above statement, we use  goto  After the statement , The execution order of the statements has changed , That is, execute the statement block first  2, Then execute the statement block  1.

 Besides , It should be noted that  goto  Statement cannot jump into a loop statement , You can't jump out of the scope of a class .

 because  goto  Statement is not easy to understand , therefore  goto  Sentences are not commonly used .
 Class access modifier : Used to set access restrictions on classes , Include  public、internal  Or don't write , use  internal  Or not writing means that the class can only be accessed in the current project ;public  Represents that the class can be accessed in any project .
 Modifier : A modifier is a description of the characteristics of a class itself , Include  abstract、sealed  and  static.abstract  It means Abstract , Classes that use its modifier cannot be instantiated ;sealed  The decorated class is the sealed class , You can't   Be inherited ;static  The decorated class is a static class , Can't be instantiated .
 Class name : The class name is used to describe the function of a class , Therefore, it is better to have practical significance when defining class names , This makes it easy for users to understand the content described in the class . Class names must be unique in the same namespace .
 Class members : Elements that can be defined in a class , It mainly includes fields 、 attribute 、 Method 
 Members in a class include fields 、 attribute 、 Method . Each class member needs to specify an access modifier when defining 、 Modifier .

 There are two main access modifiers for class , namely  internal  and  public, If the access modifier is omitted , That is to say  internal.

 The access modifiers of members in the class are  4  individual , The usage is as follows .
1) public
 Members can be accessed by any code .
2) private
 Members can only be accessed by code in the same class , If you don't use any access modifiers before class members   operator , The default is private.
3) internal
 Members can only be accessed by code in the same project .
4) protected
 Members can only be accessed by code in a class or derived class . Derived classes are involved in inheritance , It will be described in detail later .

 The definition of fields is similar to the definition of variables and constants described earlier , Just add an access modifier before a variable or constant 、 Modifier .

 When decorating a field, you usually use two modifiers , namely readonly ( read-only ) and static ( Static ).

 Use  readonly  Decorating a field means that you can only read the value of the field and cannot assign a value to the field .

 Use  static  The decorated field is a static field , You can access this field directly through the class name .

 It should be noted that constants cannot be used  static  Modifier modifier .
 The syntax form of the definition method is as follows .
 Access modifier      Modifier      return type      Method name ( parameter list )
{
    
     Sentence block ;
}

 among :
1)  Access modifier 
 All class member access modifiers can use , If you omit the access modifier , The default is  private.
2)  Modifier 
 When defining a method, modifiers include  virtual( Virtual )、abstract( In the abstract )、override( Rewrite the )、static( Static )、sealed( Sealed ).override  Is used when inheriting between classes .
3)  return type 
 Used to get the return result after calling the method , The return value can be any data type , If the return value type is specified , You have to use  return  Keyword returns a value that matches its type . If no return value type is specified , You have to use  void  Keyword indicates that there is no return value .
4)  Method name 
 Description of the functions implemented by the method . The method name is named after  Pascal  The nomenclature is standard .
5) parameter list 
 Allowed in method  0  To multiple parameters , If no parameter is specified, keep the parentheses of the parameter list . The definition form of the parameter is “ Data type parameter name ”, If multiple parameters are used , Multiple parameters need to be separated by commas .
原网站

版权声明
本文为[#math. h]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/178/202206270735089496.html