Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Simplify an if statement with a method C#

I was wondering if there is any possible way to simplify this.

if (string != "")
{
   dataGridView1.Rows.Add(string);
}

All I can find is how to shorten if statements which return a value, not execute a method like mine.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There is not much to do from where you are already. I would only suggest inverting the if statement to reduce nesting. You could also remove the braces by using this method like this:

if (string == "") return;
dataGridView1.Rows.Add(string);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading