English 中文(简体)
列入清单的序号[] 名单
原标题:Add strings to List<string[]> list
  • 时间:2011-11-24 11:45:36
  •  标签:
  • c#
  • .net

I m new to C#, I need to do the following:

我需要宣布名单

List<string[]> myList = new List<string[]>();

现在,列入清单的条件和内容应当如下(用假守则):

for int i = 0 to N
if nNumber == 1 add string[i] to myList[0]
else to myList[1]

最后,我名单上将有2名成员,每个成员都有若干人。

我不敢肯定,我如何能够把这些插手作为方法添加到各位成员身上:,在名单上插入成员,我不想这样做。

问题回答
        var myList = new List<string>[] { new List<string>(), new List<string>() }; 

        for (int i = 0; i <= 12; i++)
        {
            if (i == 1)
                myList.Last().Add(i.ToString());
            else
                myList.First().Add(i.ToString());
        }

根据我可以看到的情况,你不需要一个阵列清单。

var myList = new List<string>[] { new List<string>(), new List<string>() };

现在,你应该能够完全按照你的要求执行。

This can be also performed as List of List of string as below:

    List<List<string>> strList = new List<List<string>>();
    for (int i = 0; i < N; i++)
    {
        if (nNumber == 1)
            strList[0].Add(i.ToString());
        else
            strList[1].Add(i.ToString());
    }

在我的餐厅,我有以下定义:

enum gic_rpt_columns{AGYDIV, STS, GICID, LASTNAME,IRSTNAME, CudeAGE, DESCRIPTION , PREMIUM, RUNDATE, BILMO, EMPLOYERPERCENT };

public class csv_parser
{
    .
    .
    .
    private string[]        m_column_headings;
    List<string[]>          m_csv_array = new List<string[]>();
    .
    .
    .

下面的法典将添加一栏标题,然后在卷宗中添加行文。

               using (TextFieldParser parser = new TextFieldParser(m_csv_path))
                {
                    parser.TextFieldType = FieldType.Delimited;
                    parser.SetDelimiters(",");

                    if (!parser.EndOfData)
                    {
                        m_column_headings = parser.ReadFields();
                        m_csv_array.Add(m_column_headings);
                    }

                    while (!parser.EndOfData)
                    {
                        string[] fields = parser.ReadFields();
                        m_csv_array.Add(fields);
                        m_row_count++;
                    }
                }




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签