0

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.

6
  • Would you please clarify more your question? and it it's possible can u put some code exampl? Commented Apr 18, 2011 at 20:55
  • 2
    I'm still not sure what you want to do. I'm reading it for the 10th time now. Commented Apr 18, 2011 at 20:56
  • 1
    have you really tried to find the answer yourself? Commented Apr 18, 2011 at 20:56
  • Guys, you're all very smart and everything, but I think we are all just guessing here :) Commented Apr 18, 2011 at 21:01
  • looks like you need to .ToString() the values assuming the list is not generic or contains objects. Commented Apr 18, 2011 at 21:11

4 Answers 4

6

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.

Sign up to request clarification or add additional context in comments.

2 Comments

He could also look at the ToArray() method of List<> msdn.microsoft.com/en-us/library/bb298736.aspx
@Justin why would you do that when it already has an Item property with an index?
2

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];

Comments

2

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?

Comments

0

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?

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.