Is there a reason System dll is different in Silverlight and other C # libraries

The reason I ask is because I wrote an extension method for use in Silverlight to find out that this function magically began to work in silver light.

Example

string sentence = "I am a sentence that has some words"; sentence.Contains("N"); //would return false, silverlight true sentence.Contains("n"); //would return true, silverlight true 

Why is there a special system dll in the Silverlight platform that makes comparison as an insenstive case?

I came across this for many methods, it is annoying that they either act differently or are simply absent at all.

+6
source share
1 answer

The reason I ask is because I wrote an extension method for use in Silverlight just to find out that this function magically began to work in silver light.

There is a public bool string.Contains(string) method public bool string.Contains(string) for all .NET versions starting from version 2.0 ( 2.0 , 3.0 , 3.5 , 4.0 , SL 3/4 WP 7.0 / 7.1 ).

It is interesting to note that the SL version is specified only from SL 3/4 - is it possible that you updated the solution 2.0? . Then this could be taken into account.

Otherwise, a particular method always takes precedence over an extension method, so your extension method should never be called (we can exclude .NET 1.1, since the C # 1.2 compiler does not include extension methods).

For MSDN.NET 2.0 documents, this is how:

This method searches for words (case-sensitive and culture-sensitive) using the current culture. The search starts from the first character position of this line and continues to the last character position.

All other versions (including Silverlight) are listed as:

This method performs an ordinal (case-sensitive and culture-insensitive) comparison. The search starts from the first character position of this line and continues to the last character position.

If you see otherwise (please check the high frequencies), this may be a wireframe error ... but I cautiously expect a simpler explanation.

+3
source

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


All Articles