小编GMa*_*ika的帖子

Initialize Dictionary <string,List <string >>

我想知道如何声明/初始化字典?下面给出了错误.

Dictionary<string, List<string>> myD = new Dictionary<string, List<string>>()
{
  {"tab1", MyList }
};

List <string> MyList = new List<string>() { "1" };
Run Code Online (Sandbox Code Playgroud)

错误是:字段初始值设定项不能引用非静态字段,方法或属性MyList.它不是字典前面或后面的List声明.

c# dictionary

6
推荐指数
3
解决办法
1万
查看次数

如何消除尾随空行/列

我正在使用Microsoft Interop将excel文件转换为csv文件.我使用sheet.SaveAs函数.

我的初始Excel工作表包含从A1到AZ列的数据,共100行.我在CSV中只需要从A1到AP的数据,只需50行.

使用Range函数,我删除了row51-100,我清除了相同行的内容,当我保存为CSV时,我发现行51-100如下:(只是逗号).我不想在CSV中看到这些逗号.

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

对于AQ-AZ列也是如此.我不希望这些数据以CSV格式显示.我删除,使用范围功能清除内容,但这些AQ-AZ列在CSV文件中显示为",,,,,,,,,,,,,,,,,,,,,".

有没有办法将XLS保存为CSV,只有我希望在CSV文件中看到的范围.有没有办法控制进入CSV文件的范围?

简而言之,我想在CSV文件中看到50行的A1到AP列的数据.没有空的尾随","s.有办法吗?

c# csv excel interop xls

5
推荐指数
1
解决办法
5600
查看次数

通过迭代列表来访问每个对象的常用方法

我有多种类型的对象实例从公共接口继承.我想通过迭代列表或arraylist或集合来访问每个对象的常用方法.我怎么做?

    {

    interface ICommon
    {
        string getName();
    }

    class Animal : ICommon
    {
        public string getName()
        {
            return myName;
        }
    }

    class Students : ICommon
    {
        public string getName()
        {
            return myName;
        }
    }

    class School : ICommon
    {
        public string getName()
        {
            return myName;
        }
    }


   }
Run Code Online (Sandbox Code Playgroud)

当我在对象[]中添加动物,学生和学校时,尝试以类似的循环访问

for (loop)
{
   object[n].getName // getName is not possible here. 
   //This is what I would like to have.
or 
   a = object[n];
   a.getName // this is also not working. 
}
Run Code Online (Sandbox Code Playgroud)

是否可以从列表或集合中访问不同类型的公共方法?

c# arrays collections interface arraylist

4
推荐指数
1
解决办法
73
查看次数

标签 统计

c# ×3

arraylist ×1

arrays ×1

collections ×1

csv ×1

dictionary ×1

excel ×1

interface ×1

interop ×1

xls ×1