Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create custom constant suffix in C#

Tags:

c#

.net

i am trying to develop a class for unlimited size integer values, all i need is to make a new custom constant suffix used with the assign operator.

For example:

lets assume the class name is BigInt and the Suffix created is B

the assign statement will be like this

// B character will tell the compiler about the New Data Type
BigInt x = 111111111111111111111111111111111111111111111111B; 

is there any way to achieve this?

Special Regards

like image 230
Ali Safi Avatar asked Dec 01 '22 22:12

Ali Safi


1 Answers

No. The language / compiler do not support this. Something close, which you might want to look into is an implicit conversion operator. That would let you do something like this:

BigInt b = "1234";

public class BigInt
{
    public static implicit operator BigInt(string value)
    {
        return new BigInt {Value = value};
    }
    public string Value { get; private set; }
}
like image 108
Joseph Sturtevant Avatar answered Dec 26 '22 00:12

Joseph Sturtevant