I'm not sure if my question is worded right, but I have a class that needs to make a property available to any class that instantiates it, but not make that property public. As an example:
public class MyClass1
{
private double _PrivateNum = 9499488.07;
private double PrivateNum
{
get
{
return _PrivateNum;
}
}
}
I want to create an instance of MyClass1 inside of MyClass2 and be able to access PrivateNum
from MyClass2, but I don't want PrivateNum
to be available outside of MyClass2. I know private double PrivateNum
is not the correct, of course.
public class MyClass2
{
public MyClass1 myclass1 = new MyClass1();
public double GetSomeData
{
double PrivateNum = myclass1.PrivateNum; <<== How do I set this in MyClass1
} so I can access it in MyClass2,
} but be unavailable outside
of MyClass2?
I just whipped up this example to illustrate what I'm wanting to accomplish. As I recall, VB uses shared
to accomplish this. How is it done in C#?
MyClass1` contains information about options/accessories a user has chosen for the base product. Most times, the options/accessories price is intended to be displayed to the user for choices they have made for the product, but sometimes the option/accessory acts as a base price modifier. The requirement in these isolated cases is to deduct the option price from the base price, but the option price should not be seen or transmitted to the client. This class gets sent as Json so I don't want it publicly accessible.
– rwkiii Aug 22 '14 at 20:18