简体   繁体   中英

C# StringCollection in Custom Class

Given the class below, what would be the correct way to add multiple strings to the StringCollection called blob_key_col_name?

public class blob_info
{
    public string column_name { get; set; }
    public string blob_value { get; set; }
    public int column_pos { get; set; }
    public string blob_key { get; set; }
    public int blob_key_count { get; set; }
    public StringCollection blob_key_col_name { get; set; }


    public blob_info(string column_name, string blob_value, int column_pos, string blob_key, int blob_key_count)
    {
        this.column_name = column_name;
        this.blob_value = blob_value;
        this.column_pos = column_pos;
        this.blob_key = blob_key;
        this.blob_key_count = blob_key_count;
        blob_key_col_name = new StringCollection();
    }
}

public static List<blob_info> blob_col = new List<blob_info>();

void main
{
   blob_col.Add(new blob_info("Column_name","pathname",0,"key_column_name",0,blob_key_col_name.Add("")));
}

That would be to use:

string[] myStringArray = new[] {"aa","bb","cc"};
blob_col.blob_key_col_name.AddRange(myStringArray);

Checkout the documentation for more details. https://msdn.microsoft.com/en-us/library/system.collections.specialized.stringcollection(v=vs.110).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM