当前位置:网站首页>C#修饰符
C#修饰符
2022-07-02 09:45:00 【A_tuohai】
- 所谓的面向对象是指在编程时将任何事物都看成是一类对象来描述。对象包括属性和方 法,属性是指对象固有的特征,方法则是对象的行为。面向对象语言的三大特征分别是封 装、继承、多态。
- 定义一个类应该要有属性和方法(所属的属性及方法一定是该类事务所共有的)关键字class用于修饰一个类

- 这个类包含了许多关键字,比如public、private、class、int等等
- 那么这几个关键字是什么意思呢?那么我就来一一解答,public : 即公共的的意思,代表这个类是对外公开的。 class:即类的意思,用于修饰一个类。 private:即私有的意思,代表这个类是私有化的。类是私有化的。 Person:在此代表类名。 height、age:字段名,在此被称为成员变量。 int:基本数据类型之一,代表一个整数。

- 接下来是访问修饰符:4个访问修饰符是添加到类、结构或成员声明的关键字,一共有5个,分别是public、Internal、Private、Protected、protected internal;那么这几个修饰符是什么意思呢,Public:公有的,是类型和类型成员的访问修饰符。对其访问没有限制。 Internal:内部的,是类型和类型成员的访问修饰符。同一个程序集中的所有类都可以访问。Private:私有的,是一个成员访问修饰符。只有在声明它们的类和结构中才可以访问。 Protected:受保护的,是一个成员访问修饰符。只能在它的类和它的派生类中访问。protected internal:访问级别为 internal或protected。即“同一个程序集中的所有类,以及所有程序集中的子类都可以访问。
- 成员的修饰符在修饰字段时通常用两个修饰符,即readonly(只读)、static(静态)、const(常量),三者不能修饰同一个成员,使用readonly修饰字段意味着只能读取该字段的值儿不能给字段赋值。使用static修饰的字段是静态字段,可以直接通过类名访问该字段。
- 成员的默认值字段在类中定义完成后,在类加载时,会自动为字段赋值,不同数据类型的字段默认值不同,如图

- 一个成员或类型只有有一个访问修饰符,使用protected internal组合时除外,如果在成员声明中未指定访问修饰符,则使用默认的可访问性,接下来是类型成员默认的可访问性。

这是我所学到的C#修饰符了,所以我要分享给你们,希望可以帮助到你们。
以上就是我的分享,新手上道,请多多指教。如果有更好的方法或不懂得地方欢迎在评论区教导和提问喔!
边栏推荐
- Input box assembly of the shutter package
- BOM DOM
- 深拷貝 事件總線
- CPU指令集介绍
- About wechat enterprise payment to change x509certificate2 read certificate information, publish to the server can not access the solution
- Find the common ancestor of any two numbers in a binary tree
- BOM DOM
- Less than three months after the programmer was hired, the boss wanted to launch the app within one month. If he was dissatisfied, he was dismissed immediately
- Use sqoop to export ads layer data to MySQL
- CDA data analysis -- common knowledge points induction of Excel data processing
猜你喜欢

High performance erasure code coding

spfa AcWing 851. spfa求最短路

Map and set

Go学习笔记—多线程

JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)

Adding database driver to sqoop of cdh6

Floyd AcWing 854. Floyd求最短路

寻找二叉树中任意两个数的公共祖先

Redis transaction mechanism implementation process and principle, and use transaction mechanism to prevent inventory oversold

深拷貝 事件總線
随机推荐
BOM DOM
Intel 内部指令 --- AVX和AVX2学习笔记
ASP. Net MVC default configuration, if any, jumps to the corresponding program in the specified area
Docsify deploy IIS
JSON序列化 与 解析
Drools executes the specified rule
LeetCode—<动态规划专项>剑指 Offer 19、49、60
Introduction to CPU instruction set
计算二叉树的最大路径和
JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
Sort---
drools执行完某个规则后终止别的规则执行
"As a junior college student, I found out how difficult it is to counter attack after graduation."
Addition, deletion, modification and query of MySQL table (Advanced)
趣味 面试题
bellman-ford AcWing 853. 有边数限制的最短路
High performance erasure code coding
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
Discrimination of the interval of dichotomy question brushing record (Luogu question sheet)
About wechat enterprise payment to change x509certificate2 read certificate information, publish to the server can not access the solution