我正在尝试学习C#中的索引器,我想知道为什么s=new string(toArray)
返回我在s
类型为string
的变量中输入的值,以及为什么{{ 1}}正在返回对象的类型?
Access.cs
s = toArray.ToString()
Program.cs
namespace TestApplication
{
class Access
{
public string s = "hello";
public String st { set; get; }
public char this[int index]
{
get { return s[index]; }
set
{
char[] toArray = s.ToCharArray();
toArray[index] = value;
s = new string(toArray);
//s = toArray.ToString();
}
}
}
}