Reputation: 4779
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
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
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
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
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