|
Obviously, reflecting the assembly won't catch that. Inspecting and decompiling the IL would.
/ravi
|
|
|
|
|
Not in the case where the app gets the name of the required assembly from a database. 
|
|
|
|
|
Or if the app uses a web service to look up the connection string before accessing the db. Of course, it has to first look up the .disco resource in order to find the web service.
It's lunch time and the air is heavy with the aroma of spicy chicken with rice. Mmm mm!
/ravi
|
|
|
|
|
Ravi Bhavnani wrote: It's lunch time and the air is heavy with the aroma of spicy chicken with rice. Mmm mm!
I wonder if they anything like that near where I'll be at lunch time today... there's supposed to be a McDonald's, but now you have me thinking on a higher level.
|
|
|
|
|
How do I invoke a method from a dll written in .NET 2.0 from .NET 1.1?
|
|
|
|
|
|
Hello everyone,
Two questions,
1.
How foreach utilizes the IEnumerator interface and IEnumerable interface? Any there any docuements? I am interested in it.
2.
Pros and cons compared with using foreach and using simple index variable to iterate? Like,
for (int i = 0; i < abc.Count; i++)
{
}
thanks in advance,
George
|
|
|
|
|
Foreach basically just calls GetEnumerator() on your collection, and then repeatedly calls MoveNext() on the enumerator to move through the collection.
No real difference. If your interested in performance, try it and time it, I suspect it makes nears as no difference.
Only con I can think of is that you can't modify a collection (add/remove) while you are foreaching through it, but you could if you just looped with an index (Although I wouldn't recommend it, you'd most likely screw something up, and miscount with your index or something)
Personally, I use for each most of the time. I can't think of the last time I used a normal for loop to go through a collection.
Simon
|
|
|
|
|
for is useful if you want to delete an item from a collection.
|
|
|
|
|
Cool, Pete!
regards,
George
|
|
|
|
|
You're welcome. BTW - the issue I'm referring to here is that you can't delete an item in an enumerator. It really doesn't like it.
|
|
|
|
|
Correct, thanks Pete!
regards,
George
|
|
|
|
|
Thanks Simon,
Your answer is complete.
regards,
George
|
|
|
|
|
Yeah, what they said.
Plus, some times a method takes a parameter of type IEnumerable so foreach is about the only option open to you, contrasted with a method that takes an array and you can choose.
If you have the choice to use foreach , for , or while and all you are trying to do is find one item in the collection; then foreach is somewhat frowned upon.
|
|
|
|
|
PIEBALDconsult wrote: If you have the choice to use foreach, for, or while and all you are trying to do is find one item in the collection; then foreach is somewhat frowned upon.
Why?
Simon
|
|
|
|
|
Because you're not actually doing something with "each" item. It's a conceptual distinction.
|
|
|
|
|
Good point. I like that. I'll would normally use a while loop when purely searching for an item (mainly because 'break' feels a bit messy), but I'll admit to using foreach sometimes. I won't do it any more. That's a dam good reason.
Thanks
Simon
|
|
|
|
|
Simon Stevens wrote: I'll would normally use a while loop when purely searching for an item (mainly because 'break' feels a bit messy),
Good man that man.
|
|
|
|
|
I think using foreach with a conditional break is fine, why do you think it is bad design, Simon?
regards,
George
|
|
|
|
|
George_George wrote: why do you think it is bad design,
It tends to be an indication of poorly thought out implementation. If you are using a break statement, then this means that you know what the end condition is for getting out is, and it's not a count based condition.
|
|
|
|
|
Thanks for your clarification, Pete!
regards,
George
|
|
|
|
|
Why do you think it is "conceptual distinction", PIEBALDconsult? Any more descriptions?
regards,
George
|
|
|
|
|
Why do you think "foreach is somewhat frowned upon", PIEBALDconsult?
regards,
George
|
|
|
|
|
Hi EveryOne,
I am writing a windows application that Refers a COM component which exposes a single function called Connect(). I have referenced COM Component but I don't know how to call this function on a button click.
In VB we create a variable and then set an instance of the class object to the varibale, finally browsing this variable with a dot operator would reveal the methods exposed by the class. How do we achieve the same in C#?
I am new to C# so kindly excuse me if this is very basic and I am wasting your valuable time. Thanks.
Regards,
LG.
lgatcodeproject
|
|
|
|
|
lgatcodeproject wrote: In VB we create a variable and then set an instance of the class object to the varibale, finally browsing this variable with a dot operator would reveal the methods exposed by the class. How do we achieve the same in C#?
The same works in C#. You use the New operator to create a new instance.
MyClass myObject = new MyClass();
myObject.SomeMethod();
If you want to do something on a button click, you just find the handler for the click event for the button, and put the code in their.
Post your code. Which bit are you having trouble with?
Simon
|
|
|
|