当前位置:网站首页>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#修饰符了,所以我要分享给你们,希望可以帮助到你们。
以上就是我的分享,新手上道,请多多指教。如果有更好的方法或不懂得地方欢迎在评论区教导和提问喔!
边栏推荐
- 浏览器存储方案
- 线性DP AcWing 897. 最长公共子序列
- Is the neural network (pinn) with embedded physical knowledge a pit?
- Enhance network security of kubernetes with cilium
- Rust search server, rust quick service finding tutorial
- arcgis js 4.x 地图中加入图片
- Redis sentinel mechanism and configuration
- 深拷贝 事件总线
- 模块化 CommonJS ES Module
- What data types does redis have and their application scenarios
猜你喜欢

arcgis js 4.x 地图中加入图片

AI mid stage technology research

Go学习笔记—多线程

深拷贝 事件总线

AI中台技术调研

Embedded Software Engineer career planning

Bom Dom

What is the relationship between NFT and metauniverse? How to view the market? The future market trend of NFT

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

Brush questions --- binary tree --2
随机推荐
线性DP AcWing 898. 数字三角形
IPhone 6 plus is listed in Apple's "retro products" list
Simple use of drools decision table
Go learning notes - go based interprocess communication
高性能纠删码编码
What data types does redis have and their application scenarios
Leetcode - < dynamic planning special> Jianzhi offer 19, 49, 60
How to write a pleasing English mathematical paper
The programmer and the female nurse went on a blind date and spent 360. He packed leftovers and was stunned when he received wechat at night
[ybtoj advanced training guidance] cross the river [BFS]
Multiply LCA (nearest common ancestor)
Mysql database foundation
MySQL indexes and transactions
Mui WebView down refresh pull-up load implementation
一些突然迸发出的程序思想(模块化处理)
模块化 CommonJS ES Module
Docsify deploy IIS
哈希表 AcWing 840. 模拟散列表
上传文件时,服务器报错:IOFileUploadException: Processing of multipart/form-data request failed. 设备上没有空间
Shutter encapsulated button