当前位置:网站首页>Definition of C class and method
Definition of C class and method
2022-04-23 06:24:00 【Wood acridine】
C# Definition of classes and methods
The definition of a class
grammar : Class access modifier Modifier class( keyword ) Class name { Class members }
example :

explain :
Class access modifier : Used to set access restrictions on classes .
Respectively public Indicates that the class can be accessed in any project 、internal or Omit not to write Indicates that the class can only be accessed in the current project .
Modifier : A modifier is a description of the characteristics of a class itself .
abstract It means Abstract , Classes that use its modifier cannot be instantiated ;
sealed The decorated class is the sealed class , uninheritable ;
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 . Class names are unique in the same namespace .
Members of the class : Elements defined in the class , It mainly includes Field 、 attribute 、 Method .
Class member access modifier :
public: Members can be accessed by any code .
private: Members can only be accessed by code in the same class , If the access modifier is not used before the class member , The default is private
internal Members can only be accessed by code in the same project .
protected Members can only have code access to classes or derived classes .
Member modifier :readonly( read-only )、static( Static class ) and const( Constant ), Three cannot decorate the same member .
readonly Decorating a field means that you can only read the value of the field and cannot assign a value to the field .
static The decorated field is a static field , The modified class is called static class , You can access this field directly through the class name .
about static For members , It doesn't belong to any object , It belongs to all objects , The current class .
example :static int personCount = 0;
const Constants cannot be accessed externally , All names are required to be capitalized .
example :public const string TYPE = " A good man ";
public string GetPersonType()
{
return TYPE;
}
C# The method in
Method definition
grammar : Access modifier Modifier return type Method name ( parameter list ){ Sentence block }
example :

explain :
Access modifier : All class member modifiers can use , The default is private.
Modifier : Yes virtual( Virtual )、abstract( In the abstract )、override( Rewrite the )、static( Static )、sealed( Sealed ).
virtual Set the method to virtual , Is a key modifier
abstract A modified class is called an abstract class and will be defined by a derived class , The method of modification is called abstract method .
override Is inherited between classes, is used .
sealed The seal cannot be rewritten . uninheritable
static Static modification method is called static modification method , The modified class is called static class .
Static and non static members are called difference :
Non static members :1 Need to be called by the object 2. Static members can be called
Static members :1 Can only be called by class name 2. Non static members cannot be called
return type : Use if there is a return value return, If there is no return value, use void
Method name : use Pascal Nomenclature , Capitalize each word .
parameter list : There can be 0 To more than one , Keep parentheses without parameters , Multiple are separated by commas . The form of the definition ( data type Parameter name )
example :static void AddOne(int value)
{
value++;
}
get and set accessor
For classes, attributes are generally not exposed , Realization get and set The accessor is encapsulated . Used for value taking and assignment .
example :string name;
public String Name
{
get { return name; }
set { name = value + "_1";}
}
example :public int sex { get; set; }
版权声明
本文为[Wood acridine]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210616405319.html
边栏推荐
- Collection and map thread safety problem solving
- Pytoch -- data loading and processing
- JSP syntax and JSTL tag
- Stability building best practices
- Failure to deliver XID in Seata distributed transaction project
- 图像恢复论文——[RED-Net, NIPS16]Image Restoration Using Very Deep Convolutional Encoder-Decoder Networks wi
- PyTorch笔记——实现线性回归完整代码&手动或自动计算梯度代码对比
- Pytorch learning record (7): skills in processing data and training models
- Calculation (enter the calculation formula to get the result)
- Filebrowser realizes private network disk
猜你喜欢
![Paper on Image Restoration - [red net, nips16] image restoration using very deep revolutionary encoder decoder networks wi](/img/1b/4eea05e2634780f45b44273d2764e3.png)
Paper on Image Restoration - [red net, nips16] image restoration using very deep revolutionary encoder decoder networks wi

Techniques et principes de détection

線性代數第二章-矩陣及其運算

container
![Denoising paper - [noise2void, cvpr19] noise2void learning denoising from single noise images](/img/9d/487c77b5d25d3e37fb629164c804e2.png)
Denoising paper - [noise2void, cvpr19] noise2void learning denoising from single noise images

檢測技術與原理

IO multiplexing of 09 redis

Linear algebra Chapter 1 - determinant

PyTorch笔记——观察DataLoader&用torch构建LeNet处理CIFAR-10完整代码

Programming record - picture rotation function SciPy ndimage. Simple use and effect observation of rotate()
随机推荐
Fundamentals of digital image processing (Gonzalez) I
How does MySQL convert stored seconds into dates
PyTorch笔记——实现线性回归完整代码&手动或自动计算梯度代码对比
Use Matplotlib. In Jupiter notebook Pyplot server hangs up and crashes
Example of reentrant lock thread waiting to wake up
Reading of denoising paper - [ridnet, iccv19] real image denoising with feature attention
Understanding and installing MySQL
Numpy common function table sorting of data processing
[leetcode 6] zigzag transformation
In depth source code analysis servlet first program
去噪论文阅读——[RIDNet, ICCV19]Real Image Denoising with Feature Attention
Generate excel template (drop-down selection, multi-level linkage)
PyTorch笔记——观察DataLoader&用torch构建LeNet处理CIFAR-10完整代码
lambda expressions
Understanding and use of tp50, tp90 and tp99
Framework analysis 1 Introduction to system architecture
Protected (members modified by protected are visible to this package and its subclasses)
Preparedstatement prevents SQL injection
[leetcode 383] ransom letter
MySQL advanced query