2 Des 2011

Tips: Simplify your ‘OR’ Logic in C#.NET

I think I do have a little tips for you to share. Not very significant tips, but you can use it for your daily practice.

Sometimes when you want to use a logic like this, it’s too long to write code.

Old Code
  1. if (Fld.Type == SPFieldType.Choice || Fld.Type == SPFieldType.Note || Fld.Type == SPFieldType.Integer || Fld.Type == SPFieldType.Number)
  2.     FieldContent = (string)Li[Fld.Id];

But you can simplify your code using this code below.

Simpler Code
  1. if (",Text,Note,Choice,Integer,Number,".Contains(Fld.TypeAsString))
  2.     FieldContent = (string)Li[Fld.Id];

Happy coding…! Winking smile