views:

161

answers:

5

What are some of the bad practices you have seen in C# or .NET in general, there are plenty of posts on "good" practices, but I have not seen one on bad practices.

If this is OT then please delete.

A: 

Not using LINQ where appropriate.

Donut
Also - using LINQ when not appropriate.
Lee
@Lee Good point.
Donut
A: 

a simple bad practice that comes to mind is to concat strings with +

string bigString = smallstring1 + smallstring2 + smallstring3 + ...

instead of using StringBuilder

ArsenMkrt
Actually, your example is compiled to `string bigString = String.Concat(smallstring1, smallstring2, smallstring3, ...)` which is efficient. Concatenating strings across **multiple lines** is inefficient.
Greg
That's Great Greg! I didn't know it!
ArsenMkrt
A: 
if (boolCondition == true)
{
   // do x
}
else
{
   // do  y
}

Instead of:

if (boolCondition)
{
   // do x
}
else
{
   // do  y
}
Oded
+1  A: 

Should all be listed here.

Yuriy Faktorovich
A: 
string s = "H"+"e"+"l"+"l"+"o"+" "+"w"+"o"+"r"+"l"+"d";
Stefanvds
Constant string concatenations are optimized by the compiler. This has no runtime cost over that of "Hello world".
Eric Lippert
This is a great practice! If you want your code to be unreadable =D
bloparod
Eric, bad practice isn't just about 'de-optimizing' things for the compiler... readability and maintainability are prior to that most of the time.
Stefanvds