Fórmulas e Cenas

Object Reference Not Set to an Instance of an Object

  Home  |   Contact  |   Syndication    |   Login
  44 Posts | 0 Stories | 13 Comments | 0 Trackbacks

News

Archives

Post Categories

Links

Fun

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

DateTime.Parse(DateTime.Now.ToShortDateString()).ToString("dd-MM-yyyy")

 

The right way:

 

DateTime.Now.ToString("dd-MM-yyyy")

 

 

 


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;