Linked Questions

333 votes
9 answers
402k views

What is the purpose of the Using block in C#? How is it different from a local variable?
Ryan Michela's user avatar
  • 8,414
75 votes
14 answers
91k views

Are there particular instances where I should (or shouldn't?) be using "using" blocks: using(SomeType t = new SomeType()){ ... }
22 votes
14 answers
54k views

i want to know what is the use of "using" keyword in c#, i am new to it.. when we need to use "using" keyword.. i googled it, could not be satisfied with answers. still i want to know some more from ...
Naruto's user avatar
  • 9,654
4 votes
7 answers
6k views

I'm new to C#,been a pascal lover until I found C# in Depth.In Delphi there is a try{} statement that is also implemented in C#. However,I've seen some of you mentioning "Using(){} is better than try{...
Ivan Prodanov's user avatar
0 votes
6 answers
643 views

I see loads of code snippets with the following Syntax using (RandomType variable = new RandomType(1,2,3)) { // A bunch of code here. } why not just declare the variable and use it? This Using ...
Omar Kooheji's user avatar
  • 55.9k
5 votes
6 answers
2k views

DUPE: Uses of "using" in C# I have seen people use the following and I am wondering what is its purpose? Is it so the object is destroyed after its use by garbage collection? Example: ...
user avatar
3 votes
1 answer
1k views

Hi I was going through some examples in C# and came across some code similar to below : private void WriteData(string filePath) { using var writer = new System.IO.StreamWriter(filePath); //...
Jasmeet's user avatar
  • 1,495
0 votes
5 answers
221 views

I have the following code: try { using (var context = new DataContext()) { if (!context.Database.Exists()) { ...
user avatar
-1 votes
2 answers
314 views

Do I really need to use comm.Dispose() and conn.Dispose() or directly used the using? using (OdbcConnection conn = new OdbcConnection()) { conn.Open(); OdbcCommand comm = new OdbcCommand(sql, ...
user avatar
0 votes
2 answers
197 views

I'm not talking about references to assemblies, rather the using statement within the code. For example what is the difference between this: using (DataReader dr = .... ) { ...stuff involving data ...
Mark Roworth's user avatar
1 vote
3 answers
161 views

I'm doing a tutorial on how to save a text file with StreamWriter. I understand how to do it but I started reading a tutorial on the StreamWriter Class to get a better understanding of it. In an ...
user avatar
2 votes
2 answers
87 views

I am not sure how to use using statement correct. I try like this: [HttpDelete("{ClubId}", Name = "DeleteOpenings_Club")] public async Task<IActionResult> ...
JdDEV's user avatar
  • 43
5 votes
0 answers
275 views

A simple console application, in Visual Studio 2019, .Net Framework 4.7, Windows: static void Main(string[] args) { try { Console.WriteLine("In try"); throw new ...
S Itzik's user avatar
  • 564
0 votes
1 answer
240 views

I got stuck in the weeds of how IDisposable and the GarbageCollector work. Suppose you have an IDisposable object, which doesn't actually have an resources that it's holding onto (but the Dispose() ...
Brondahl's user avatar
  • 8,743
-2 votes
2 answers
104 views

Considering the follow code can someone explain to me why and why not to use 'using'? I've read about the rule of thumb with IDisposable but why is IDisposable the determining factor? private string ...
Gabriel W's user avatar
  • 155

15 30 50 per page
1
2 3 4 5
7