What's the best way to solve it?
I have tried :
using System;
using System.Globalization;
using System.Linq;
using System.Collections.Generic;
class HelloWorld {
static void Main() {
List<CultureInfo> CultureInfos = CultureInfo
.GetCultures(CultureTypes.SpecificCultures)
.ToList();
var a = CultureInfos.Where(x => x.DisplayName.Contains("Israel"))
.FirstOrDefault();
Console.WriteLine(a?.DisplayName.Split(' ')[0]);
}
}
Funny thing, It works on onlinegdb.com but doesn't work on my local machine .Net core 3.1. It returns Null in "a" Tried to find any clue to their .Net version - no success
Do you know why? / What I'm doing wrong?
Thanks
Ok it seems like RegionInfo contains the plain country name.
Using EnglishNameso you have a baseline. If you use DisplayName it depends on the CurrentCulture if your code works.
For example on a german system "Austria" would'nt work, but "Österreich"
var cultureInfo = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
.FirstOrDefault(c => new RegionInfo(c.Name).EnglishName == "Israel"));
See working example here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With