s = new string(toArray)和s = toArray.ToString()有什么区别?

时间:2018-09-11 19:58:56

标签: c# indexer

我正在尝试学习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();
            }
        }

     }
  }

0 个答案:

没有答案