Can CultureInfo.CurrentCulture ever be null?
A null value would crash my program, which I don’t want. So I’m asking, to be safe, do I need to do?
var culture = CultureInfo.CurrentCulture ?? CultureInfo.InvariantCulture
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
It definitely looks like it’s guaranteed to be non-
null:Thread.CurrentCulturethrows an exception if you try to set it tonull, so it’s logical to assume that having a non-nullvalue is an invariant.Apart from this,
CultureInfo.CurrentCulturegives the algorithm that determines its initial value:Again, this doesn’t leave open the option of a
nullvalue.