Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
What is the difference between private and protected functions in c#?

Private : This can access only within the class. This function can access only within that class. We can not call this function using objects of the class.
Correct ?

Protected: I dont have any idea.

Public: This can be accessible outside the class.

Correct ?
Posted
Updated 1-Jan-19 19:55pm

 
Share this answer
 
Comments
Am Gayathri 3-Feb-15 4:58am    
Very good link..Thanks Amersh
Amresh Bahadur Singh 3-Feb-15 5:01am    
welcome ..
Protected - Its means that type is assisible with in your class and class which is deriving it.

example
C#
public class A
{
   protected int prop1 {get;set;}//accessible in class 
}

public class B :A
{
  //this class can access prop1
}

public class c
{
  //as this class is not deriving from class , it not allowed to access prop1 
}

i hope i m clear and this will help you
 
Share this answer
 
Comments
Am Gayathri 3-Feb-15 5:17am    
Thanks...

public class A
{
private int prop1 {get;set;}//accessible in class
}

public class B :A
{
//Can this class access prop1 ?
}
Pranay Rana 3-Feb-15 5:45am    
no because prop1 is private variable you need to make it Protected...if you want to access it
Am Gayathri 3-Feb-15 7:30am    
OK Thanks
Pranay Rana 3-Feb-15 7:43am    
dont forget to upvote and accept answe r

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