LINQ not working for strings in Xamarin?

I have the following function:

private static string SanitizeVersionStringFromUnit(string version) { var santizedString = new string(version.Where(char.IsLetterOrDigit).ToArray()); ; return santizedString; } 

However, intellisense tells me that the line does not contain a Where definition and that the extension method was not found. I have using System.Linq; declared in the file. In a project other than Xamarin, this code works fine.

This is the PCL Xamarin.Forms project in the VS2015 community. What gives?

+5
source share
1 answer

You get an error because the PCL string version does not implement IEnumerable<char> . You can use Cast to compile code:

 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 the String class implement IEnumerable in a portable library?

+10
source

Source: https://habr.com/ru/post/1247781/


All Articles