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
What is static and use of it?
What is int32 in c#?
Can we inherit sealed class in c#?
Why delegates are safe in c#?
So let's say I have an application that uses myapp.dll assembly, version 1.0.0.0. There is a security bug in that assembly, and I publish the patch, issuing it under name myapp.dll 1.1.0.0. How do I tell the client applications that are already installed to start using this new myapp.dll?
What does break do in loop?
Can dictionary have duplicate keys c#?
Why var is used in c#?
What is c sharp used for?
What are value types and reference types?
Why do I get an error (cs1006) when trying to declare a method without specifying a return type?
What the different phase/steps of acquiring a proxy object in webservice?
What is application c#?
How do you create empty strings in c#?
Is the following code legal?