Possible Duplicate:
using statement with multiple variables
I have several disposable object to manage. The CA2000 rule ask me to dispose all my object before exiting the scope. I don't like to use the .Dispose()
method if I can use the using clause. In my specific method I should write many using in using:
using (Person person = new Person()) { using (Adress address = new Address()) { // my code } }
Is it possible to write this on another way like:
using (Person person = new Person(); Adress address = new Address())
Adjective I began receiving duplicate copies of the magazine every month. I had a duplicate key made.
To remove duplicate values, click Data > Data Tools > Remove Duplicates. To highlight unique or duplicate values, use the Conditional Formatting command in the Style group on the Home tab.
On the Home tab, in the Styles group, click Conditional Formatting > Highlight Cells Rules > Duplicate Values… The Duplicate Values dialog window will open with the Light Red Fill and Dark Red Text format selected by default. To apply the default format, simply click OK.
You can declare two or more objects in a using
statement (separated by commas). The downside is that they have to be the same type.
Legal:
using (Person joe = new Person(), bob = new Person())
Illegal:
using (Person joe = new Person(), Address home = new Address())
The best you can do is nest the using statements.
using (Person joe = new Person()) using (Address home = new Address()) { // snip }
The best you can do is:
using (Person person = new Person()) using (Address address = new Address()) { // my code }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With