几天前我开始用C#编程.
现在,当玩弄运算符重载时会出现一个令人困惑的错误.
以下代码在运行时生成StackOverflowException:
using System;
namespace OperatorOverloading
{
public class Operators
{
// Properties
public string text
{
get
{
return text;
}
set
{
if(value != null)
text = value;
else
text = "";
}
}
// Constructors
public Operators() : this("")
{
}
public Operators(string text)
{
// Use "set" property.
this.text = text;
}
// Methods
public override string ToString()
{
return text;
}
// Operator Overloading
public static string operator +(Operators lhs, Operators rhs) …Run Code Online (Sandbox Code Playgroud)