Posts

Showing posts from March, 2010

Session and Cache are By Reference

Recently a colleague remarked that if he got a List of some type out of the ASP.NET Cache, and changed an item, the Cache item would also change. That is correct. Session (InProc) , Cache and Application all return "live" references. A good writeup on this can be found by friend and fellow MVP Rick Strahl here: http://www.west-wind.com/Weblog/posts/1214.aspx If you do not want this behavior, you need to either delete the Session / Cache / Application object and replace it with what you want later, or store a clone by duplicating the object, doing your work on the original that you got out of Cache, then replacing the existing cached item with your clone that was not changed. for example: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace CachebyRef { public class Person { public String FirstName { get; set; } public String LastName { get; set; } } p

When Job Growth Is Not Job Growth

The Department of Labor just reported that in February, employment fell by fewer-than-expected 36,000 jobs with the unemployment rate steady at 9.7%. While we may hear the Obama Administration or Harry Reid trying to spin this as some sort of economic victory for their stimulus or otherwise trying to put the best face on the economy, this is in reality not very good news. Let us remember that job growth needs to be around 125,000 jobs gained per month just to keep up with US population growth. To make up the roughly 10 million jobs it would take to get us to an employment situation about where we were near the peak of the economy, we'd have to see job growth of 350,000 per month for four years straight. Such a scenario seems unlikely while we live under the umbrella of the Obama-Pelosi-Reid cartel. The Obama Administration has quintupled, in just one year, the deficits that took its predecessor Bush eight years to create. Looking at the current stagnation in employment, in large pa

String.Empty vs “” vs String. IsNullOrEmpty

I was reading up on this recently and a couple of interesting points came to light: myString = “” creates a new instance of type String. myString = String.Empty does not. The key item is doing comparisons. Here’s some sample test code: class Program { static void Main(string[] args) { String myString = ""; long a, b, c, d, e, f; Console.WriteLine("Method 1..."); a = DateTime.Now.Ticks; for (int index = 0; index < 100000000; index++) { bool isEmpty = myString == ""; } b = DateTime.Now.Ticks; Console.WriteLine("Method 2..."); c = DateTime.Now.Ticks; for (int index = 0; index < 100000000; index++) { bool isEmpty = myString.Length == 0; } d = DateTime.Now.Ticks; Console.WriteLine("Method 3..."); e = DateTime.Now.Ticks; for (int index = 0; index < 100000000; index++) { bool isEmpty = String.IsNullOrEmpty(myString); } f = DateTime.Now.Ticks; var Method1 = b - a; var Method2 = d - c; var Method3 =