Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Is there any way to access private memebers of an object
from another object?

Answers were Sorted based on User's Feedback



Is there any way to access private memebers of an object from another object?..

Answer / mohit jethva

You need to create a property with private field and make
property as public so you can access private field using
public property in other object.

eg.

private int _ID;

public int ID
{
get{return value;}
set{_ID = value;}
}

Is This Answer Correct ?    10 Yes 1 No

Is there any way to access private memebers of an object from another object?..

Answer / porchelvi.a

We can achieve this by using Reflection.
By using Reflection we can access some information about
object at runtime.even we can invoke private method of an
object by using Reflection.

Example :

Class Student
{
private int RollNo;
public string Name;
}
class MainClass
{
Type type=typeof(Student); //to get type information
MemberInfo[] mem=type.getMembers();
foreach(Memberinfo m in mem)
//we can get every member here
}

Is This Answer Correct ?    6 Yes 0 No

Is there any way to access private memebers of an object from another object?..

Answer / rajesh

In C++ we can access private members of one class by the
object of another class,befor that we have to
make "friend"(keyword) the respective member of the first
class to the second class
for ex:
class A
{
private void display();
};

inherits: class B
{
friend void display();
};
Now we can acess the 'display' function using classB
object.We can only make friend to the immediate inherited
class and not to all classes under inheritance.

and in C# we have to create a property as first answer

Is This Answer Correct ?    0 Yes 1 No

Is there any way to access private memebers of an object from another object?..

Answer / sitaram

no, we can't access private members in another
object.because private members are accessing only that
class or object.

Is This Answer Correct ?    1 Yes 6 No

Post New Answer

More C Sharp Interview Questions

How do you convert byte array to hexadecimal string, and vice versa?

0 Answers  


What is unmannaged code and will CLR handle this kind of code or not .

0 Answers   DELL,


What?s the top .NET class that everything is derived from?

7 Answers  


Distinguish between array and arraylist in c#?

0 Answers  


What is a static field?

0 Answers  


use of operator overloading of implicit & explicit operators?

1 Answers   TCS,


can any one send the project manager questions in .net

1 Answers  


how to prevent a class from being inherited in c#.net?

0 Answers  


What is view state c#?

0 Answers  


What is the difference between decimal and integer?

0 Answers  


What is yield keyword?

0 Answers  


Why reflection is used in c#?

0 Answers  


Categories