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?