我正在尝试制作自定义变量,但被卡住了。
我还是 C# 的新手,所以我猜我只是不知道发生了什么。
struct MyCustomStringVariable
{
public static implicit operator MyCustomStringVariable(string input)
{
return input;
}
}
class Program
{
static MyCustomStringVariable myCustomString = "This is a string!";
static void Main(string[] args)
{
Console.WriteLine(myCustomString);
Console.ReadLine();
}
}
抛出以下异常
System.StackOverflowException:“引发了‘System.StackOverflowException’类型的异常。”