在列表中列出c#.NET问题 [英] List in List c# .NET question

查看:79
本文介绍了在列表中列出c#.NET问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题。

是否可以将列表添加到列表中?



包装类

I have the following question.
Is it possible to ad an list into a list?

Wrapper class

public List<Analyses> HaalAnalyseOp(DataSource requestedDataSource)
        {
            IDataSource source;

            switch (requestedDataSource)
            {
                case DataSource.Access:
                    source = new AccessDataSource();
                    break;
                case DataSource.MsSql:
                    source = new MsSqlDataSource();
                    break;
                case DataSource.WebService:
                    source = new WebServiceDataSource();
                    break;
                default:
                    throw new ArgumentOutOfRangeException("requestedDataSource");
            }

            return source.GetAnalyses();
        }

        public class MsSqlDataSource : IDataSource
        {
            public List<Analyses> GetAnalyses()
            {
                //code to get MsSql data
                throw new NotImplementedException();
            }
        }

        public class AccessDataSource : IDataSource
        {
            public List<Analyses> GetAnalyses()
            {
                var lijst = new List<Analyses>();
                lijst.Add(new Analyses() { Stappen = "OdbcDataAdapter da = new OdbcDataAdapter();" });                                      // list 1
                return lijst;
            }
        }

        public class WebServiceDataSource : IDataSource
        {
            public List<Analyses> GetAnalyses()
            {
                //code to get WebService data
                throw new NotImplementedException();
            }
        }
    }





IDataSource类



IDataSource class

public class Analyses
    {
        public List<string> Stappen { get; set; }          //List 2
    }

    public interface IDataSource
    {
        List<Analyses> GetAnalyses();
    }

推荐答案

使用List.AddRange(集合为IEnumerable(Of T))方法。



请参考以下链接: -

http://stackoverflow.com/questions/2369673/how-to-add-list-to-a-list-in-asp-net [ ^ ]

http://stackoverflow.com/questions/5671493/ adding-listt-add-another-list [ ^ ]
Use List.AddRange(collection As IEnumerable(Of T)) method.

refer below links:-
http://stackoverflow.com/questions/2369673/how-to-add-list-to-a-list-in-asp-net[^]
http://stackoverflow.com/questions/5671493/adding-listt-add-another-list[^]


List<list><int>> list = new List<list><int>>();
    var rand = new Random();
    for (int i = 0; i < 10; i++)
    {
        List<int> sublist = new List<int>();
        int top = rand.Next(1, 15);
        for (int v = 0; v < top; v++)
        {
        sublist.Add(rand.Next(1, 5));
        }
        list.Add(sublist);





这是我们如何在列表中列出的一个小例子

让我知道如果有帮助



this is the small example to how we can list inside list
let me know if its help or not


这篇关于在列表中列出c#.NET问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆