variable check – c#

I am getting accustomed to using the single line ‘If’s.. they are very handy inside the getter-setter. You basically do it like this..

private string m_someVariableName;
Public string SomeVariableName{
get { return someVariableName == null? “my_default_text”: someVariableName; }
set {m_someVariableName = value ; }
}

What if there is a boolean variable? well, you might not even need to check it like this, but I thought maybe we could use something like..

private bool m_someVariableName;
Public bool SomeVariableName{
get { return someVariableName.ToString() == null? true : someVariableName; }
set {m_someVariableName = value ; }
}

and if it is a string [ ] array? I am trying this out, lets see if it works.

private string[ ] m_someVariableName;
Public string [ ] SomeVariableName{
get { return someVariableName.Length==0? “do something” : m_someVariableName ; }
set {m_someVariableName = value ; }
}

If any of you are using similar methods for quicker processing, or if any of these codes helped you, leave me a note!

Advertisements

One thought on “variable check – c#

  1. It sure reduces the number of lines but sometimes it also reduces readability. Only use it for simple purposes.

    Cheers!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s