0

I need to check that I get the int value which is the valid LCID of CultureInfo. Unfortunately, CultureInfo doesn't contain something like bool TryGetCultureInfo(int, out CultureInfo) method. Also I see that some CultureInfo items have the same LCID.

So I can use this way:

var lcids = CultureInfo.GetCultures(CultureTypes
    .AllCultures).Select(c => c.LCID).OrderBy(
    c => c).ToArray(); // it contains duplicates

HashSet<int> repeated = new HashSet<int>();

for (int i = 1; i < lcids.Length; i++) {
    if (lcids[i] == lcids[i - 1]) {
        repeated.Add(lcids[i]);
    }
}

foreach (var item in repeated) {
    Console.WriteLine(item);
}

Output:

4
4096
31748

I can check wether repeated variable contains the checked value, but it seems bad for me... Also I can try to use constructor inside of try\catch block but it is bad method because it will be used in iteration and can decrease the speed.

How can I check LCID validation without try\catch block and without my code which I show before?

Andrey Bushman
  • 11,712
  • 17
  • 87
  • 182
  • LCID was deprecated 10 years ago, it could no longer scale to handle the ever increasing number of cultures supported by Windows. Replaced by culture names that were already common in .NET, like "en-US". It is completely unclear why you want to use it, just don't. – Hans Passant Oct 11 '16 at 16:40
  • AutoCAD application uses LCID in the registry subkey names. For example: ACAD-E001:409. At this case 409 is LCID. I parse such strings. – Andrey Bushman Oct 11 '16 at 17:51
  • @AndreyBushman : Did you get any answer for this? (I also need solution for this situation) – Muthukrishnan R Jan 07 '21 at 06:33

0 Answers0