F
Frank Rizzo
Given the inneficiencies of ArrayList and Hashtable on 64-bit systems, I
am converting them to List<> and Dictionary<> respectively. It's a
pretty massive system, so there are a lot of casts. For instance.
ArrayList aaa = new ArrayList();
aaa.Add(new Customer());
aaa.Add(new Customer());
aaa.Add(new Customer());
Customer c = (Customer) aaa[0];
With generics, it would be like this:
List<Customer> aaa = new List<Customer>();
aaa.Add(new Customer());
aaa.Add(new Customer());
aaa.Add(new Customer());
Customer c = aaa[0]; //e.g. without the cast
But, given that I simply changed declarations from ArrayList to List<>,
there is still a lot of code that has a cast, even though the cast is
from a strongly typed list:
Customer c = (Customer) aaa[0];
So changing declarations to generics was pretty easy, but the there are
about a zillion casts in the system. So I have 2 questions.
1. Is the compiler smart enough take out the unnecessary casts?
2. Is there a setting in VS2005 that will show me the unnecessary casts
when compiling?
Thanks.
am converting them to List<> and Dictionary<> respectively. It's a
pretty massive system, so there are a lot of casts. For instance.
ArrayList aaa = new ArrayList();
aaa.Add(new Customer());
aaa.Add(new Customer());
aaa.Add(new Customer());
Customer c = (Customer) aaa[0];
With generics, it would be like this:
List<Customer> aaa = new List<Customer>();
aaa.Add(new Customer());
aaa.Add(new Customer());
aaa.Add(new Customer());
Customer c = aaa[0]; //e.g. without the cast
But, given that I simply changed declarations from ArrayList to List<>,
there is still a lot of code that has a cast, even though the cast is
from a strongly typed list:
Customer c = (Customer) aaa[0];
So changing declarations to generics was pretty easy, but the there are
about a zillion casts in the system. So I have 2 questions.
1. Is the compiler smart enough take out the unnecessary casts?
2. Is there a setting in VS2005 that will show me the unnecessary casts
when compiling?
Thanks.