I am trying to create a new data type and have a property in property Value in the class.
I can access and manipulate the properties from within the class. However, while accessing the value from outside, I must use it as instance.Value.
Is it possible to set the property by assigning the value to the instance directly, perhaps like we use indexers for array based classes?
For example, what I want to do is this:
public class NewNumberType<T>
{
public T Value {get; set;}
}
From the calling class, I want to use the the NewNumberType as:
NewNumberType<double> d = new NewNumberType<double>();
// d.Value = 15; I dont want to do this
d = 15; // I want to refer the instance this way.
Using Structs for the job may not be ideal. For instance structs don't allow parameterless constructors.. It would throw "structs cannot contain explicit parameterless constructors" error.
It would be always desirable to use a class instead.