Click here to Skip to main content
14,084,501 members
Rate this:
 
Please Sign up or sign in to vote.
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

   
Comments
Am Gayathri 3-Feb-15 4:58am
   
Very good link..Thanks Amersh
Amresh Bahadur Singh 3-Feb-15 5:01am
   
welcome ..
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Protected - Its means that type is assisible with in your class and class which is deriving it.

example
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
   
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190518.1 | Last Updated 2 Jan 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100