Click here to Skip to main content
15,901,751 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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 ?
Posted
Updated 5-Jan-17 23:04pm
v2
Comments
F-ES Sitecore 5-Jan-17 6:34am    
Consult the MSDN documentation

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[^].
 
Share this answer
 
Comments
Arslan saif 5-Jan-17 6:54am    
Thanks really help full :) for me
Pete O'Hanlon 5-Jan-17 6:55am    
You're welcome.
Peter Leow 5-Jan-17 6:59am    
5ed! Thank you.
 
Share this answer
 
Comments
Pete O'Hanlon 5-Jan-17 6:49am    
5 from me.
Arslan saif 5-Jan-17 6:54am    
Thanks really help full :) for me
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)[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900