tagged [using]

Unused using statements

Unused using statements I may already know the answer to this question, but I thought it was worth asking anyway. If I have a load of `using` statements within my code file that being used; 1. Does t...

17 Jun at 12:13

C# conditional using block statement

C# conditional using block statement I have the follow code but it is awkward. How could I better structure it? Do I have to make my consuming class implement IDisposable and conditionally construct t...

8 Dec at 16:17

Where do I put try/catch with "using" statement?

Where do I put try/catch with "using" statement? > [try/catch + using, right syntax](https://stackoverflow.com/questions/4590490/try-catch-using-right-syntax) I would like to `try/catch` the following...

29 Jul at 05:18

The type or namespace name could not be found

The type or namespace name could not be found I have a `C#` solution with several projects in `Visual Studio 2010`. One is a test project (I'll call it ""), the other is a `Windows Forms Application` ...

What happens if i return before the end of using statement? Will the dispose be called?

What happens if i return before the end of using statement? Will the dispose be called? I've the following code The `dispose()` method is called at the end of `using` statement braces `}` right? Since...

Combining foreach and using

Combining foreach and using I'm iterating over a ManageObjectCollection.( which is part of WMI interface). However the important thing is, the following line of code. : The point is that ManageObject ...

9 Jun at 11:32

VS 2015 - C# simplify/truncate using namespaces

VS 2015 - C# simplify/truncate using namespaces I would prefer the following Visual Studio 2015, does the following I figured out, that I can change the behavior for the code hint (IDE0001) by adjusti...

Do you need to call Flush() on a stream or writer if you are using the “using” statement?

Do you need to call Flush() on a stream or writer if you are using the “using” statement? I am not sure whether I need to call `Flush()` on the used objects if I write something like this: Are they al...

24 Jan at 10:22

What are the benefits of maintaining a "clean" list of using directives in C#?

What are the benefits of maintaining a "clean" list of using directives in C#? I know VS2008 has the remove and sort function for cleaning up using directives, as does Resharper. Apart from your code ...

24 Oct at 21:9

Identify IDisposable objects

Identify IDisposable objects i have to review a code made by some other person that has some memory leaks. Right now i'm searching the disposable objects to enclause them with the using statement and ...

overhead to unused "using" declarations?

overhead to unused "using" declarations? I've just installed resharper and it's letting me know the namespaces i'm not actually using in each of my classes. which lead me to the question - is there ac...

13 Mar at 02:16

How is performance affected by an unused using directive?

How is performance affected by an unused using directive? Visual Studio will automatically create using statements for you whenever you create a new page or project. Some of these you will never use. ...

14 Jul at 19:5

Will Dispose() be called in a using statement with a null object?

Will Dispose() be called in a using statement with a null object? Is it safe to use the `using` statement on a (potentially) null object? Consider the following example: ``` class Test { IDisposable...

20 Dec at 16:30

Catching Exception inside Using statement

Catching Exception inside Using statement I know that [Using](http://msdn.microsoft.com/en-us/library/yh598w02%28v=vs.100%29.aspx) statement disposes out the object that is being created. Like if I wa...

17 Apr at 14:57

what does a using statement without variable do when disposing?

what does a using statement without variable do when disposing? I've always used using with variable and assignment. Now i have like this a class DbProviderConnection: ``` public class DbProviderConne...

24 Feb at 12:55

Is there a list of common object that implement IDisposable for the using statement?

Is there a list of common object that implement IDisposable for the using statement? I was wondering if there was some sort of cheat sheet for which objects go well with the using statement... `SQLCon...

Create a temporary file from stream object in c#

Create a temporary file from stream object in c# Given a stream object which contains an xlsx file, I want to save it as a temporary file and delete it when not using the file anymore. I thought of cr...

9 Mar at 17:32

C# exiting a using() block with a thread still running onthe scoped object

C# exiting a using() block with a thread still running onthe scoped object What happens to a thread if it is running a method in an object that was freed by exiting a using block? Example: () is runni...

23 Jun at 14:1

Do I have to Close() a SQLConnection before it gets disposed?

Do I have to Close() a SQLConnection before it gets disposed? Per my other [question here about Disposable objects](https://stackoverflow.com/questions/1033334/is-there-a-list-of-common-object-that-im...

When is "using" block used for in C#? How to use "using" block in C#?

When is "using" block used for in C#? How to use "using" block in C#? I saw that in most samples `SqlCommand` was used like this ``` using (SqlConnection con = new SqlConnection(CNN_STRING)) { using...

29 Dec at 04:58

Does Stream.Dispose always call Stream.Close (and Stream.Flush)

Does Stream.Dispose always call Stream.Close (and Stream.Flush) If I have the following situation: Can I just call `MySW.Dispose()` and sk

26 May at 15:57

The C# using statement, SQL, and SqlConnection

The C# using statement, SQL, and SqlConnection Is this possible using a using statement C# SQL? ``` private static void CreateCommand(string queryString, string connectionString) { using (SqlConne...

29 Aug at 13:20

If an Exception happens within a using statement does the object still get disposed?

If an Exception happens within a using statement does the object still get disposed? If an Exception happens within a using statement does the object still get disposed? The reason why I'm asking is b...

24 Jan at 16:53

Try/Finally block vs calling dispose?

Try/Finally block vs calling dispose? Is there any difference between these two code samples and if not, why does `using` exist? vs: I mean in the second example you really shoul

Are there any side effects of returning from inside a using() statement?

Are there any side effects of returning from inside a using() statement? Returning a method value from a using statement that gets a DataContext seems to always work , like this: ``` public static Tra...

3 Mar at 09:6