Dear Sir/Mam,
Please have a look in my Name class below
which is intended to Use Like Built in sealed String Class : -
public class NameField
{
readonly string _value;
public NameField(string value)
{
this._value = value;
}
public static implicit operator string(NameField d)
{
if (d._value.Length > 5) throw new System.Exception("");
return d._value;
}
public static implicit operator NameField(string d)
{
return new NameField(d);
}
}
now we can set values like:-
NameField myName="Sanjeeb Kumar Chaudhary"
Now I want to Show Conditional Compile Time error like below:-
- if string length is greater than 10 then "can not be greater than 10 characters "
- if string length is less than 5 then "can not be less than 5 characters "
- and much more as per requirements ....
Thus, kindly suggest how to do so ?