实现ac#接口

use*_*017 -7 c# datatable interface

我有一个名为myResult的dataTable,它有两列Process和ParentProcess,我试图把它放到一个Ienumerable类型中,所以我可以用Json.net序列化它.

原帖是这里的:

现在我到了这一点,我有这个界面:

namespace myFirstCProgramIn2013
    {
        public interface Interface1 : IEnumerable
        {
            string Process { get; set; }
            string ParentProcess { get; set; }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我在这个类中实现了它:

public class myArray : Interface1
{

    public string Process
    {
        get
        {
            throw new NotImplementedException();
        }
        set
        {
            throw new NotImplementedException();
        }
    }

    public string ParentProcess
    {
        get
        {
            throw new NotImplementedException();
        }
        set
        {
            throw new NotImplementedException();
        }
    }

    public System.Collections.IEnumerator GetEnumerator()
    {
        throw new NotImplementedException();
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我尝试使用此类使用以下代码将myResult分配给它:

   List<Interface1> recordList = new List<Interface1>();
   if (myResult.Rows.Count > 0)
   {
       foreach (DataRow row in myResult.Rows)
       {
           var myArray = new myArray();
           myArray.Process = Convert.ToString(row["Process"]);
           myArray.ParentProcess = Convert.ToString(row["ParentProcess"]);

       }
   }
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

App_Web_hi4zxnmq.dll中出现"System.NotImplementedException"类型的异常,但未在用户代码中处理

它是在myArray类的Process属性的set子句中抛出的.

我哪里错了?谢谢.

Zdr*_*nev 5

您在属性的setter上抛出NotInprementedException.如果你想要自动属性替换

    get
    {
        throw new NotImplementedException();
    }
    set
    {
        throw new NotImplementedException();
    }
Run Code Online (Sandbox Code Playgroud)

    get; set;
Run Code Online (Sandbox Code Playgroud)