Click here to Skip to main content
15,896,063 members
Home / Discussions / C#
   

C#

 
AnswerRe: creating an unsafe array in C# Pin
DaveyM6914-Jun-10 11:10
professionalDaveyM6914-Jun-10 11:10 
GeneralRe: creating an unsafe array in C# Pin
Luc Pattyn14-Jun-10 11:17
sitebuilderLuc Pattyn14-Jun-10 11:17 
GeneralRe: creating an unsafe array in C# Pin
DaveyM6914-Jun-10 11:49
professionalDaveyM6914-Jun-10 11:49 
GeneralRe: creating an unsafe array in C# Pin
Luc Pattyn14-Jun-10 11:52
sitebuilderLuc Pattyn14-Jun-10 11:52 
Questionusing statement equivalent Pin
Al Beback14-Jun-10 5:06
Al Beback14-Jun-10 5:06 
AnswerRe: using statement equivalent Pin
Eddy Vluggen14-Jun-10 5:16
professionalEddy Vluggen14-Jun-10 5:16 
GeneralRe: using statement equivalent Pin
Al Beback14-Jun-10 5:24
Al Beback14-Jun-10 5:24 
GeneralRe: using statement equivalent Pin
Eddy Vluggen14-Jun-10 5:55
professionalEddy Vluggen14-Jun-10 5:55 
Al Beback wrote:
that article doesn't address my specific example where a variable is not explicitly declared inside the using statement.


Ah, my bad; it does almost the same the same thing, with the difference that you don't have a reference to your class. It still creates a class, disposing it in the finally.
C#
public static void Main(string[] args)
{
    using (new SomeIDisposableClass())
    {
        Console.WriteLine("Hello World!");
    }
    Console.ReadKey(true);
}

..translates to..
IL
.method public hidebysig static 
  void Main(string[] args) cil managed
{
    .entrypoint
    .maxstack 2
    .locals init (
        [0] class using_test.SomeIDisposableClass CS$3$0000,
        [1] bool CS$4$0001)
    L_0000: nop 
    L_0001: newobj instance void 
              using_test.SomeIDisposableClass::.ctor()
    L_0006: stloc.0 
    L_0007: nop 
    L_0008: ldstr "Hello World!"
    L_000d: call void [mscorlib]System.Console::WriteLine(string)
    L_0012: nop 
    L_0013: nop 
    L_0014: leave.s L_0026
    L_0016: ldloc.0 
    L_0017: ldnull 
    L_0018: ceq 
    L_001a: stloc.1 
    L_001b: ldloc.1 
    L_001c: brtrue.s L_0025
    L_001e: ldloc.0 
    L_001f: callvirt instance void 
              [mscorlib]System.IDisposable::Dispose()
    L_0024: nop 
    L_0025: endfinally 
    L_0026: nop 
    L_0027: ldc.i4.1 
    L_0028: call valuetype 
              [mscorlib]System.ConsoleKeyInfo 
              [mscorlib]System.Console::ReadKey(bool)
    L_002d: pop 
    L_002e: ret 
    .try L_0007 to L_0016 finally handler L_0016 to L_0026
}

I are Troll Suspicious | :suss:

AnswerRe: using statement equivalent Pin
J4amieC14-Jun-10 5:22
J4amieC14-Jun-10 5:22 
GeneralRe: using statement equivalent Pin
Al Beback14-Jun-10 5:51
Al Beback14-Jun-10 5:51 
AnswerRe: using statement equivalent [modified] Pin
dan!sh 14-Jun-10 5:46
professional dan!sh 14-Jun-10 5:46 
GeneralRe: using statement equivalent Pin
Al Beback14-Jun-10 5:58
Al Beback14-Jun-10 5:58 
GeneralRe: using statement equivalent Pin
dan!sh 14-Jun-10 6:01
professional dan!sh 14-Jun-10 6:01 
GeneralRe: using statement equivalent Pin
Eddy Vluggen14-Jun-10 6:02
professionalEddy Vluggen14-Jun-10 6:02 
GeneralRe: using statement equivalent Pin
dan!sh 14-Jun-10 6:19
professional dan!sh 14-Jun-10 6:19 
GeneralRe: using statement equivalent Pin
Not Active14-Jun-10 7:35
mentorNot Active14-Jun-10 7:35 
GeneralRe: using statement equivalent Pin
Al Beback14-Jun-10 6:04
Al Beback14-Jun-10 6:04 
AnswerRe: using statement equivalent PinPopular
harold aptroot14-Jun-10 6:01
harold aptroot14-Jun-10 6:01 
GeneralRe: using statement equivalent Pin
Eddy Vluggen14-Jun-10 6:06
professionalEddy Vluggen14-Jun-10 6:06 
GeneralRe: using statement equivalent Pin
harold aptroot14-Jun-10 6:12
harold aptroot14-Jun-10 6:12 
GeneralRe: using statement equivalent Pin
Al Beback14-Jun-10 6:18
Al Beback14-Jun-10 6:18 
Questiondatagrid in Compact Frame work Pin
jashimu14-Jun-10 4:49
jashimu14-Jun-10 4:49 
AnswerMessage Closed Pin
14-Jun-10 7:19
stancrm14-Jun-10 7:19 
GeneralRe: datagrid in Compact Frame work Pin
jashimu18-Jun-10 9:12
jashimu18-Jun-10 9:12 
QuestionFold all code in all of the project with one command Pin
Neo1010114-Jun-10 4:29
Neo1010114-Jun-10 4:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.