Posts

Showing posts from July, 2011

Dynamic keyword in .Net 4.0 with ExpandoObject

[TestFixture] publicclass TestDynamic { [Test] publicvoid Test() { dynamic test = new ExpandoObject(); test.FirstName = "Michael"; test.SecondName = "Jordan"; Console.WriteLine(string.Format("{0} {1}",test.FirstName,test.SecondName)); } }

C# Stopwatch to measure time

[TestFixture] publicclass TestStopwatch { [Test] publicvoid test() { //using System.Diagnostics; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); //long running taskint sleeptime = new Random().Next(1, 3)*1000; Console.WriteLine("Running for ~{0}ms:",sleeptime); Thread.Sleep(sleeptime); stopwatch.Stop(); Console.WriteLine(stopwatch.Elapsed.ToString()); Console.WriteLine(new DateTime(stopwatch.Elapsed.Ticks).ToString("ss:fff")); } }