Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Your Opinion On This Syntax
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01427920
Message ID:
01428130
Views:
65
If your method code is short and just 'pass through' there's really no behavioral difference. In both cases in an instance is created so the bulk of the overhead is in that.

The first syntax clears the reference immediately so it can be garbage collected immediately, but this doesn't really matter if your code just runs through a method and exits since hte garbage collection isn't immediate anyway so you get little benefit from that. The only time when this sort of thing saves you a reference instance is when you have some lengthy code that runs in a loop that keeps the local scope method active for a lengthy period of time.

Personally I don't like the first syntax - it looks wrong to me even though it works fine. If I wanted that behavior I'd still create a separate variable assign it and then null it (or dispose() it) to make the intend clear.

This sort of thing should be rare anyway though. I you have many classes that do this sort of thing you probably have a design issue and should refactor that code into static methods or some other more permanent object instance that feeds these one of method calls.

+++ Rick ---


>
>dtShopOrder = new ERP().GetShopOrderDetails(txtSerialNum.Text);
>
>
>as opposed to
>
>
>ERP erp = new ERP();
>dtShopOrder = erp.GetShopOrderDetails(txtSerialNum.Text);
>
>
>Does one work better than the other? Any reasons to do it one way over the other?
>
>Personnally, I find syntax 2 easier to read.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Reply
Map
View

Click here to load this message in the networking platform