I have the following function:
private static string SanitizeVersionStringFromUnit(string version)
{
var santizedString = new string(version.Where(char.IsLetterOrDigit).ToArray()); ;
return santizedString;
}
However, intellisense is telling me string does not contain a definition for Where and that no extension method can be found. I have using System.Linq;
declared in the file. In a non-Xamarin project this code works fine.
This is a Xamarin.Forms PCL project in VS2015 Community. What gives?
You are getting the error because PCL version of string
does not implement IEnumerable<char>
. You can use Cast
to make the code compile:
private static string SanitizeVersionStringFromUnit(string version)
{
var santizedString = new string(version.Cast<char>().Where(char.IsLetterOrDigit).ToArray());
return santizedString;
}
See this question for more details: Why doesn't String class implement IEnumerable in portable library?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With