user380432
user380432

Reputation: 4779

C# method for passing a list to separate string values

I have a List object.

How can I pass these list values to separate strings? The strings always occur in the same position as follows:

[0] = time
[1] = location
[2] = note

So I need a time, location, and note string for these values.

driver.location = log.event_data[1];

It says cannot implicitly convert to string.

Upvotes: 0

Views: 136

Answers (4)

Ry-
Ry-

Reputation: 225074

Do you want to use classes or structures? Here's an example:

public class SomeClass {
     public string Time { get; set; }
     public string Location { get; set; }
     public string Note { get; set; }
}

Though you probably shouldn't use the string type to store these values, either.

If this wasn't what you meant, can you please rephrase a bit?

Upvotes: 2

Yet Another Geek
Yet Another Geek

Reputation: 4289

If your list is called 'list' then you can just do the following

string time = list[0];
string location = list[1];
string note = list[2];

Upvotes: 2

John Batdorf
John Batdorf

Reputation: 2542

If they always appear in the same location, you should be able to use the SubString() function to parse the data out, assuming it's all in one string. Is it an array? a string, or what?

Upvotes: 0

jason
jason

Reputation: 241701

Your question is unclear but it seems like the answer is

string time = list[0];
string location = list[1];
string note = list[2];

assuming that your "list" is a List<string> named list.

Upvotes: 6

Related Questions