Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8949791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:18:02+00:00 2026-06-15T13:18:02+00:00

I have this code, when I try to get not existed culture I get

  • 0

I have this code, when I try to get not existed culture I get exception.
Is there exists method like TryGetCultureInfo, which return bool value? I don’t want to use try-catch statement

CultureInfo culture = CultureInfo.GetCultureInfo(cultureCode);
if (culture == null)
{
    culture = CultureInfo.GetCultureInfo(DefaultCultureCode);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:18:03+00:00Added an answer on June 15, 2026 at 1:18 pm

    I think there’s no such method. So you could just try-catch or check all installed cultures:

    string cultureCode = "de-DE";
    CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);
    var culture = cultures.FirstOrDefault(c => c.Name.Equals(cultureCode, StringComparison.OrdinalIgnoreCase));
    if (culture == null)
    {
        culture = cultures.FirstOrDefault(c => c.Name.Equals(DefaultCultureCode, StringComparison.OrdinalIgnoreCase));
        if (culture == null)
            culture = CultureInfo.CurrentCulture;
    }
    

    But i would prefer the try-catch, i’m sure it is more efficient.

    public bool TryGetCultureInfo(string cultureCode, string DefaultCultureCode, out CultureInfo culture)
    {
        try
        {
            culture = CultureInfo.GetCultureInfo(cultureCode);
            return true;
        } catch(CultureNotFoundException)
        {
            if (DefaultCultureCode == null)
                culture = CultureInfo.CurrentCulture;
            else
            {
                try
                {
                    culture = CultureInfo.GetCultureInfo(DefaultCultureCode);
                } catch (CultureNotFoundException)
                {
                    culture = CultureInfo.CurrentCulture;
                }
            }
        }
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code try { //AN EXCEPTION IS GENERATED HERE!!! } catch {
I have this snipped code: try{ JAXB.xmlJavaConverter(clientCommand); } catch (Exception e){ nServerFifo.add(clientCommand); } I
I have some code like this: try { doStuff(); } catch(SpecificException) { if(e.Message ==
I have a C++ DLL with code like this: LogMessage( Hello world ); try
I have some code that looks like this: foreach(var obj in collection) { try
I have this code: try: parent_comment = models.Comment.all_objects.get(id=parent_comment_id) except models.Comment.DoesNotExist: parent_comment = None if
i have this jquery code which poplautes a input selector, which should display like
I have this code: try { var _o, _l, i, _d = new Array(),
I have this code for update: public Boolean update() { try { data.put(ContactsContract.Groups.SHOULD_SYNC, true);
I have used this code to store Object to a file: try{ FileOutputStream saveFile=new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.