I have a grid, and I'm accessing each unique column via its name like so:
grid.Columns["SomeColumnA"]
However, I can only set the properties of that column if it is not null like so:
if (grid.Columns["SomeColumnB"] != null) {
grid.Columns["SomeColumnB"].Width = 100;
}
I have about 15/20 different columns which need to be set for various things, but they all need to be checked for null first. It looks a bit messy as it's 15/20 if
statements. I am wondering whether or not these if
statements are the best way to do it, or if I can implement something else to simplify it and tidy the code up. Any ideas/suggestions?