Fórmulas e Cenas

Object Reference Not Set to an Instance of an Object

  Home  |   Contact  |   Syndication    |   Login
  45 Posts | 0 Stories | 16 Comments | 0 Trackbacks



Image Galleries



Well... I cant really express my feelings for this kind of programming...

The WTF way:

DateTime myNewDate = DateTime.Parse((myOldDate.Year - 1).ToString() + "-" + myOldDate.Month.ToString() + "-" + myOldDate.Day.ToString());


The right way:

 DateTime myNewDate = myOldDate.Date.AddYears(-1);


Well, this one i simply cannot understand... why anyone would do +0 after and int.parse. Any Ideas?

int myVar = Int32.Parse(ConfigurationManager.AppSettings["mySetting"] + "") + 0;


Sometimes we find some code that... well.... I guess someone must be really REALLY high to write...


The WTF way



The right way:






In this category I will post some "creative" solutions to problems. (Code changed to protect the inocents).


// The WTF way

int  myInt = Int32.Parse(myDataTable.Rows.Count + "");

// The correct way

int  myInt = myDataTable.Rows.Count;