Assign numeric value to class

c#

Solution

I think you want an implicit cast operator.

public static implicit operator MyClass(int m) 
{
     // code to convert from int to MyClass
}

Problem

Possible Duplicate: Overloading assignment operator in C# I remember I saw this question somewhere in stack overflow but I cannot find it. Basically I will like to be able to do: ``` MyClass myClass = 5; ``` where MyClass is a class implemented by my program. I will delete this question if I can find that duplicate.

Original source

Related problems