当前位置:网站首页>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 ,-27〜27-1
byte An unsigned number , Occupy 1 Bytes ,0〜28-1
short Signed number , Occupy 2 Bytes ,-215〜215-1
ushort An unsigned number , Occupy 2 Bytes ,0〜216-1
int Signed number , Occupy 4 Bytes ,-231〜231-1
uint An unsigned number , Occupy 4 Bytes ,0〜232-1
long Signed number , Occupy 8 Bytes ,-263〜263-1
ulong An unsigned number , Occupy 8 Bytes ,0〜264-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
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 .
边栏推荐
- Manim math engine
- js用while循环计算假如投资多年的利率为5%,试求从1000块增长到5000块,需要花费多少年
- JS to determine whether the result is qualified, the range is 0-100, otherwise re-enter
- Mobile security tools -jad
- 【批处理DOS-CMD命令-汇总和小结】-批处理命令中的参数%0、%1、%2、%[0-9]、%0-9和批处理命令参数位置切换命令shift,dos命令中操作符%用法
- 碎煤机crusher
- Difference between boundvalueops and opsforvalue
- How to bind SQL statements to web buttons
- R language consumption behavior statistics based on association rules and cluster analysis
- The first part of the construction of the defense system of attack and defense exercise is the introduction and the four stages of Defense
猜你喜欢
【批处理DOS-CMD命令-汇总和小结】-批处理命令中的参数%0、%1、%2、%[0-9]、%0-9和批处理命令参数位置切换命令shift,dos命令中操作符%用法
JS to determine whether the number entered by the user is a prime number (multiple methods)
JS use switch to output whether the result is qualified
【批处理DOS-CMD命令-汇总和小结】-cmd的内部命令和外部命令怎么区分,CMD命令和运行(win+r)命令的区别,
js打印99乘法表
多表联查--07--- Hash join
无论LCD和OLED显示技术有多好,都无法替代这个古老的显示数码管
Cookie加密6
游戏六边形地图的实现
【批处理DOS-CMD命令-汇总和小结】-环境变量、路径变量、搜索文件位置相关指令——set、path、where,cmd命令的路径参数中有空格怎么办
随机推荐
JDBC operation MySQL example
L'introduction en bourse de Wild Wind Pharmaceutical a pris fin: Yu pinzeng, qui avait l'intention de lever 540 millions de RMB, a effectué un investissement P2P.
Custom palette for ggplot2
Testing network connectivity with the blackbox exporter
JS to print prime numbers between 1-100 and calculate the total number of optimized versions
RNA SEQ data analysis in R - investigate differentially expressed genes in the data!
第6届蓝桥杯
apifox学习
认识O(NlogN)的排序
Gérer 1000 serveurs par personne? Cet outil d'automatisation o & M doit être maîtrisé
JS output shape
「短视频」临夏消防救援支队开展消防安全培训授课
Publications under nature, science and cell
JS find the number of all daffodils
Stream常用操作以及原理探索
洛谷刷题心得记录
js来打印1-100间的质数并求总个数优化版
二叉树结构以及堆结构基础
JS example print the number and sum of multiples of all 7 between 1-100
MSSQL how to export and delete multi table data using statements