Sunday, 15 January 2012

c# - How to tell what is passed when no value exists -


For this code, how do you know that if there is no value in the querystring then zero is returned?

HTTP CONTRACT REFERENCES = HTPCONTEX. On; String strValue = context.Request [name];

I am asking because I never know what is being returned in many cases in the NAT framework when you do not expect it when it is not in existence.

So if context.Request [name]; Called and the name is not present in the query string, how do you know that it gives blank or empty string so that I can handle the case properly where it is not present?

Use String.IsNullOrEmpty () to check the empty string For:

  string strValue =! String.isnaloracty (reference request [name]) ?? Reference. Request [name]: "some default value";  

Or if you do not have a default value that you want to set up, then you can check later:

  if (string. IsNullOrEmpty (StrValue)) {// it is null or empty} other {// it is not}  

update

Just look at the comment if you are trying to find out that the key is not present in the collection of para (which you are using through shortcodes) which is a key If you refer, then MSDN Check Stavejhikrn.

In this case, the ultimate one is the system. compilation. Specialized. NavmeValueCollection Documentation According to the documentation, when a key is not found in the collection, then a zero value actually comes back.

So you do not have to use String.IsNullOrEmpty ()) . You simply:

  string strValue = context.Request [name] ?? "Some default values";  

If you want to set the default, or else check for null .


No comments:

Post a Comment