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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can you put two constructor with the same structure in a class?

483


Why dataset is used in c#?

511


What is razor view in c#?

448


What is a function c#?

491


How can I access the registry from c# code?

518






Explain the difference between object type and dynamic type variables in c#?

497


What is the difference between select and selectmany?

436


What is connection pooling in ado.net?

547


How do I declare a pure virtual function in c#?

588


Are arraylist faster or arrays?

488


What is .edmx file?

533


Can abstract class have parameterized constructor?

499


Write a C# program to find the Factorial of n

556


What is serialization in dot net?

479


how to stored and retrive video in Sql server using asp.net c#......?

526