创建数据视图列表时出错

Error in creating a List of Dataview

我正在尝试创建一个数据视图列表,稍后将在代码中用作函数的参数。我收到此错误 "Object reference not set to an instance of an object." 我不确定如何将数据视图列表初始化为 null

        List<DataView> dvTablesLookup = null;
        List<DataTable> dtTablesLookup = null;

        // Creating Data View
        for (int i=0; i < datatablesLookup.Count; i++ )
        {
            dvTablesLookup[i] = new DataView(datatablesLookup[i]);
            dvTablesLookup[i].Sort = sortLookup;
            dtTablesLookup[i] = dvTablesLookup[i].ToTable();
        }

假设 datatablesLookup 是 List()

var datatablesLookup = new List<DataTable>();
List<DataView> dvTablesLookup = null;
List<DataTable> dtTablesLookup = null;

dvTablesLookup = datatablesLookup.Select(dt => new DataView(dt)).ToList();
dvTablesLookup.ForEach(x => x.Sort = sortLookup);
dtTablesLookup = dvTablesLookup.Select( dv => dv.ToTable()).ToList();

尝试:

    List<DataView> dvTablesLookup = new List<DataView>();
    List<DataTable> dtTablesLookup = new List<DataTable>();

    // Creating Data View
    for (int i=0; i < datatablesLookup.Count; i++ )
    {
        DataView tempdv = new DataView(datatablesLookup[i]);
        tempdv.Sort = sortLookup;
        dvTablesLookup.Add(tempdv);                
        dtTablesLookup.Add(tempdv.ToTable());
    }