Disposables, Using & Try/Catch Blocks

后端 未结 6 1403
一向
一向 2020-12-19 05:56

Having a mental block today, need a hand verifying my logic isn\'t fubar\'ed.

Traditionally I would do file i/o similar to this:

FileStream fs = null         


        
6条回答
  •  孤城傲影
    2020-12-19 06:32

        try
        {
            FileStream fs = null;
            try
            {
               fs = File.Open("Foo.txt", FileMode.Open);
    
            }
            finally
            {
               fs.Dispose();
            }
        }
        catch(Exception)
        {
           /// Handle Stuff
        }
    

    second piece of code gets translated into this

提交回复
热议问题