I agree with you in general, I wanted to make some adnotations to your post. BTW, I think that it would have to be *much more* than 10's of thousands to observe a differnce between switch vs override. My post was about coding style, not performance. BTW max number of calls will be ~50.
// Result should look something like this
string ... myArray = new ...
foreach (string in order myArray)
foreach (string address in myArray...)
Unfortunately I do not know how to declare a field and set
Be careful when using BitConverter. It uses the endianness of your CPU, so if you're byte array is coming from a hardware device with a different endianness, your BitConverter results will be messed up.
I store two kinds of data types (Bar1 and Bar2) in the same dictionary. Both data types dervies from Foo class. I would like to extract only the Bar2 elements from the dictionary.
Here is what I got:
class Bar1 : Foo
class Bar2 : Foo
staticvoid Main(string args)
Dictionary<string, Foo> foos = new Dictionary<string, Foo>();
for(int i = 0; i < 5; i++)
foos.Add("Bar1." + i, new Bar1());
for (int i = 0; i < 10; i++)
foos.Add("Bar2." + i, new Bar2());
List<Bar2> bar2List = new List<Bar2>();
foreach (Foo foo in foos.Values)
if(foo is Bar2)
Are there any other method to extract the Bar2 elements from the dictionary into the Bar2 array (bar2List) instead of using foreach-loop and if-statment?
List<Bar2> bar2List = foos.Values.Where(f => f is Bar2).ToList<Bar2>();
... should do it.
Linq-to-objects like this is essentially doing the same thing as the foreach loop in your original suggestion, so performance wise you will gain nothing, but some people will say that the Linqed code is more readable (and in this case I think I'd agree with that).
(Ed: putting the type parameter on Where doesn't work, it tries to cast items before checking them.)
Whats wrong with a foreach loop? Do you care about speed / performance or do you care about writing elitist LINQ code or some other fancy method to impress somebody? No matter what method you use, at some level, its going to have to do a foreach loop, so why not cut out the middle man for performance reasons? People who use LINQ for every little thing often end up ripping it out down the road cuz its often much slower then just writing "normal" code. True Story.
Yeah, but my 5 line foreach loop is 2x to 3x faster then your 1 line LINQ . Don't get me wrong, I sometimes use LINQ myself. I was just pointing out that in this case, it is silly of the OP to use LINQ over a basic foreach.
Does anyone knows a form navigation framework that i can use in order to implement a winform application that shows a main form displaying a list of options, each option displays a different form, which in turn display a list of options and so on ?
It is similar to wizard but with more hierarchies.
Last Visit: 31-Dec-99 18:00 Last Update: 21-Oct-21 22:02