How to set a default property for your class
15/01/2010 Leave a comment
I’m sorry but that functionality which is known by vb developers couldn’t possible when you are codding in c# .
Also there are some other solutions but its not possible to set a default property for your your class.
you can use indexer but its not that we want:
public string this[int idx]
{
get { … }
set { … }
}
or you can overload implicit operator to do this but is also not suggested.
[System.Diagnostics.DebuggerDisplay("{Value}")] public class MyClass {
public string Value { get; set; }
public static implicit operator MyClass(string s)
{
return new MyClass { Value = s };
}
public static explicit operator string(MyClass f) { return f.Value; } public override string ToString() { return Value; } }