Archive for category Code Bash

Code Bash #5: Getting eye cancer is part of the job, i guess..

public static DateTime ToDateTime(this string date)
{
DateTime date1 = DateTime.MinValue;
string[] dateArr = null;

try
{
dateArr = date.Split(’.');

if (dateArr.Length >= 3)
[...]

Code Bash #4: TheDayAfterTomorrow.ToString();

string strDay = date.Day.ToString();

string strMonth = date.Month.ToString();

string strYear = date.Year.ToString();

 outDate = string.Concat(strDay, ".", strMonth, ".", strYear);

Code Bash #2

Find the error:

XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XmlElement root = doc.DocumentElement;

if ( doc == null )
{
throw new InvalidDataException("No valid xml");
}

………….

Code Bash #1

private string twoDigits(int s)
{
if (s < 10)
return "0" + s.ToString();
else
return s.ToString();
}

Clever people would use:

return s.ToString("D2");

Hello code bash!

That`s it, I have had enough of awesome code snippets I keep finding in projects I work on. Some of the stuff I find is just too awesome to not be shared with the world. There for from today on I will post the gems I find in the new born category “Code Bash” [...]