I have a string array, and it may contain an element with the text “mytext” within the string. eg:
mystringarray
{
[0] => "hello world";
[1] => "some of mytext";
}
I also have an array that doesn’t have the mytext text in it.
mystringarray
{
[0] => "hello world";
[1] => "some of notmy";
}
My problem is when I use:
string mytextdata = mystringarray.Single<string>(t => t.Contains("mytext")).ToString();
I get an exception for the second array as it can’t find an element that matches the expression.
Is there a quick way I can edit this one line to not throw an exception if it finds nothing, and instead just ignore? I have a lot of these lines and I don’t want to have to wrap each in an if statement.
Apologies if question isn’t clear.
This will return
nullif nothing is found, otherwise it will return astring, so you don’t need theToString(). http://msdn.microsoft.com/en-us/library/bb342451.aspx