0

i have an array which have 5 values from index 0 to 4. i want to store the values in my 5 model properties.

  public IEnumerable<fields> ConvertTList(List<string[]> rows)
    {
        var tList = new List<fields>();
        foreach (var item in rows)

        {
            var ListReading = new fields

            {
           //model properties names are:

            // date, user,campaign,adgroup,changes

            };

            tList.Add(ListReading);
        }
         return (tList);
}

this is my code when foreach is executed item get 5 values. i want to store the values in model. how i can i store them using linq

3
  • 3
    "how i can i store them using linq" In general, don't ask Linq to store something, it's purpose is to query something. Commented Sep 30, 2013 at 10:21
  • Where is the instance of the model? Is it ListReading? Are you looking for something like ListReading.date = item[0]; ListReading.user = item[1]; // etc.? Commented Sep 30, 2013 at 10:24
  • @rao check answers below Commented Sep 30, 2013 at 10:56

1 Answer 1

1

Maybe you mean something like this:

public IEnumerable<fields> ConvertTList(List<string[]> rows)
{
    return rows.Select(x => StringsToField(x));
}

fields StringsToField(string[] source)
{
    return new fields
    {
        date = source[0],
        user = source[1],
        campaign = source[2],
        adgroup = source[3],
        changes = source[4],
    };
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.