我需要C#中的访问修饰符列表 [英] I need list of access modifiers in C#

查看:101
本文介绍了我需要C#中的访问修饰符列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨亲爱的,

我在C#中学习OOP但很难搞糊涂,因为我不知道C#中有多少访问修饰符。

例如

 private int Member1; 
protected int Member2;
internal int Member3;
protected internal int Member4;



什么是Absrct,Const static 等我想要我们通常在编程中使用的修饰符的总列表< br $> b $ b

我尝试过的事情:



想要了解用于的修饰符OOP?

解决方案

访问修饰符列表如下:访问修饰符(C#参考) [ ^ ]。其他关键字(const,abstract等)是修饰符,同样有一个方便的参考这里 [ ^ ]。


阅读访问修饰符(C#编程指南) [ ^ ]


Quote:

Quote:



访问修饰符

公开:可从装配或外部装配中的任何位置访问。

私有:可在班级内访问。

受保护:可在班级和继承的班级或子班级中访问。

内部:可访问在当前的程序集中。

受保护的内部:在当前程序集和组件派生类型中可访问。

更多细节请参阅: C#中的访问修饰符是什么? [ ^ ]



摘要

抽象关键字用于将类标记为抽象。

当一个类用abstract标记时,表示类中的一个或多个方法是abstract,其中method只包含方法的声明。我必须在继承类中定义所有抽象方法。它有助于实现多态,其中一个方法可以根据需要具有多个定义。例如。如果我们采用具有抽象方法CalArea()的类Shape的示例。那么从形状继承的类Circle可以与类Rectangle有不同的定义,它再次继承自类形。

更多细节请参考抽象类 [ ^ ]



常量

这与包含像仪表这样的通用值的字段一起使用。在整个宇宙中,1米的值= 100厘米。所以它被标记为const。一旦定义了值,就不能通过应用程序更改它。

更多细节 const(C#参考) [ ^ ]



静态

一般来说静态只意味着一份每个环境都会存在。

static关键字可以与字段,属性,类,构造函数,方法,运算符和事件一起使用。静态成员属于类型本身。如果一个类用static标记,则不能创建该类的实例,即无法创建对象或无法实例化类。

它不能与索引器,析构函数和委托一起使用。 />
静态类与非静态类基本相同,但有一个区别

1.static类无法启动或者您不能使用new关键字创建变量或者类。

有关详细信息,请参阅静态(C#参考) [< a href =https://msdn.microsoft.com/en-us/library/98f28cdx.aspxtarget =_ blanktitle =New Window> ^ ]


Hi Dear,
I learn OOP in C# but little confused because i don't know how many access modifiers have in C#.
For example

private int Member1;
  protected int Member2;
  internal int Member3;
  protected internal int Member4;


what is Absrct, Const static etc i want total list of Modifiers that we usually use in Programming

What I have tried:

Want to learn about Modifiers used in OOP ?

解决方案

The list of access modifiers are here: Access Modifiers (C# Reference)[^]. The other keywords (const, abstract, etc) are Modifiers and, again, there's a handy reference here[^].


read up Access Modifiers (C# Programming Guide)[^]


Quote:

Quote:


Access Modifier
Public: Accessible from any where that means within an assemble or outside assembly.
Private: Accessible within the class.
Protected: Accessible within the class and inherited class or child class.
Internal: Accessible within the current Assembly.
Protected Internal: Accessible within the current assembly and type derived from the assemble.
For More detail Please see: What are Access Modifiers in C#?[^]

Abstract
Abstract keyword is used to mark the class as abstract.
When a class is marked with abstract that means one or more method in the class is abstract where method only contains the declaration of the method. All the abstract method must me defined in the inheriting class. It helps to implement polymorphism where one method can have multiple definition as per the requirement. for example. if we take an example of class Shape which has a abstract method CalArea(). then class Circle which is inherited from shape can have different definition from the class Rectangle which is again inherited from Class Shape.
More detail refer to Abstract Classes[^]

constant
this is used with the field which contains the universal value like meter. In the whole universe the value of 1meter=100cm. so it is marked as const. once the value is defined it cannot be changed through out the application.
For more detail const (C# Reference)[^]

static
In general static means only one copy will exist per invironment.
static keyword can be used with field, property, class, constructor, method, operator and events. static members belong to type itself. if a class is marked with static then no instance of the class can be created i.e. object can not be created or class can not be instantiated.
it cannot be used with indexers, destructors and delegates.
A static class is basically same as the non-static class but there is one difference
1.static class cannot be initiated or you cannot use new keyword to create a variable or the class.
For more detail static (C# Reference)[^]


这篇关于我需要C#中的访问修饰符列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆