Question

When I decompile String.IndexOf (String) method, I see this;

[__DynamicallyInvokable]
public int IndexOf(string value)
{
  return this.IndexOf(value, string.LegacyMode ? StringComparison.Ordinal : StringComparison.CurrentCulture);
}

In the second parameter definition:

  • if string.LegacyMode is true, StringComparison.Ordinal is evaluated.
  • if string.LegacyMode is false, StringComparison.CurrentCulture is evaluated.

But what does String.LegacyMode exactly mean?

When I decompile this property I see this:

internal static bool LegacyMode
{
  get
  {
    return CompatibilitySwitches.IsAppEarlierThanSilverlight4;
  }
}

I searched about String.LegacyMode and CompatibilitySwitches.IsAppEarlierThanSilverlight4 on Google first but I couldn't find any useful information.

Can you enlighten me?

Was it helpful?

Solution

Why not check the source, MSDN :)

Ninja edit: I just saw the link you posted at the top of your question. Select Silverlight from the other versions dropdown and you'll see the note below.

String.IndexOf Method

Notes to Callers

Starting in Silverlight 4, the behavior of the String.IndexOf(String) method has changed. In Silverlight 4, it performs a case-sensitive and culture-sensitive comparison using the current culture to find the first occurrence of value. This conforms to the behavior of the String.IndexOf(String) method in the full .NET Framework. In Silverlight 2 and Silverlight 3, String.IndexOf(String) performs an ordinal comparison. If the common language runtime determines that a Silverlight-based application was compiled using either Silverlight 2 or Silverlight 3, it performs an ordinal comparison; otherwise, it performs a culture-sensitive comparison.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top