The maximum length of the CultureInfo.Name property

Maybe someone knows what the maximum length of the CultureInfo.Name property in the .NET Framework 4.0 is.

+3
source share
3 answers

This is 11. Here is the code:

var count = CultureInfo.GetCultures(CultureTypes.AllCultures)
                       .Select(ci => ci.Name.Length)
                       .Max();
+1
source

Answer: 84

Documentation: (thanks @lethek in the comment) http://msdn.microsoft.com/en-us/library/system.globalization.cultureandregioninfobuilder.cultureandregioninfobuilder%28v=vs.100%29.aspx

I managed to create a new culture using the CultureAndRegionInfoBuilder class, whose length was 84 characters.

CultureAndRegionInfoBuilder 84 . 84 , , , "-", 8 . "ThisIsLongerThan8Characters", 8 . ( , , "_" , )

, sysglobl System.Globalization.

. CultureInfo, _.

, .

string cultureName = "qwertyui-12345678-qwertyui-12345678-qwertyui-12345678-qwertyui-12345678-qwertyui-123";
Console.WriteLine( "MAX LENGTH: " + cultureName.Length );
try {
    CultureAndRegionInfoBuilder.Unregister( cultureName );
} catch {
    Console.WriteLine( "Cannot remove culture" );
}

CultureAndRegionInfoBuilder builder = new CultureAndRegionInfoBuilder( cultureName , CultureAndRegionModifiers.None );

CultureInfo ci = new CultureInfo( "en-AU" );
RegionInfo ri = new RegionInfo( "US" );

builder.LoadDataFromCultureInfo( ci );
builder.LoadDataFromRegionInfo( ri );
builder.Register();

CultureInfo info = new CultureInfo( cultureName );

Console.WriteLine( DateTime.Now.ToString( info.DateTimeFormat.LongDatePattern ) );
Console.WriteLine( info.Name );
Console.WriteLine( info.DisplayName );

try {
    CultureAndRegionInfoBuilder.Unregister( cultureName );
} catch {
    Console.WriteLine( "Cannot remove culture" );
}
+3

:

    public static void Test()
    {
        var culturesNames = from c in CultureInfo.GetCultures(CultureTypes.AllCultures)
                            select new { c.DisplayName, c.DisplayName.Length, c.Name };


        foreach (var ci in culturesNames.OrderBy((o) => o.Length))
        {
            Console.WriteLine("{0} : {2} {1}", ci.DisplayName, ci.Length, ci.Name);
        }
    }

50. , .

0

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


All Articles