当前位置:网站首页>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
边栏推荐
- 7.Domino piling
- Practical operation - Nacos installation and configuration
- Collections multiple parameter sorting
- Supply chain service terms
- In depth understanding of the relationship between dncblevel and noise denoising in the paper
- The bottom implementation principle of thread - static agent mode
- Calculation (enter the calculation formula to get the result)
- 線性代數第一章-行列式
- LDCT图像重建论文——Eformer: Edge Enhancement based Transformer for Medical Image Denoising
- List segmentation best practices
猜你喜欢
自动控制原理知识点整合归纳(韩敏版)
图像恢复论文——[RED-Net, NIPS16]Image Restoration Using Very Deep Convolutional Encoder-Decoder Networks wi
LDCT图像重建论文——Eformer: Edge Enhancement based Transformer for Medical Image Denoising
线性代数第三章-矩阵的初等变换与线性方程组
Programming record - picture rotation function SciPy ndimage. Simple use and effect observation of rotate()
Preparedstatement prevents SQL injection
自动控制(韩敏版)
Addition, deletion, modification and query of MySQL table
container
RPC must know and know
随机推荐
图像恢复论文——[RED-Net, NIPS16]Image Restoration Using Very Deep Convolutional Encoder-Decoder Networks wi
[leetcode 6] zigzag transformation
编程记录——图片旋转函数scipy.ndimage.rotate()的简单使用和效果观察
LDCT图像重建论文——Eformer: Edge Enhancement based Transformer for Medical Image Denoising
SQL injection
Preparedstatement prevents SQL injection
Reading of denoising papers - [cvpr2022] blind2blind: self supervised image denoising with visible blind spots
JDBC operation transaction
Chapter 3 of linear algebra - Elementary Transformation of matrix and system of linear equations
Pytorch notes - get familiar with the network construction method by building RESNET (complete code)
Stability building best practices
自动控制(韩敏版)
Calculation (enter the calculation formula to get the result)
6.Reversal
Consistent hash algorithm used for redis cache load balancing
MySQL occasional Caton
Chapter 4 of line generation - linear correlation of vector systems
Programming record - picture rotation function SciPy ndimage. Simple use and effect observation of rotate()
ThreadLocal. Threadlocalmap analysis
DBCP usage