You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using(new with IDisposable{voidDispose()=>Console.WriteLine("ended")}){// ...}
The with keyword is optional if the type specified is an interface, as there is no ambiguity with collection/object initializers, which gives the syntax used in the original example.
The last variation is a type with only behaviour, no interfaces or state.
newwith{voidDo()=>Console.WriteLine("Done")}
Here with is required.
The text was updated successfully, but these errors were encountered:
The purpose of this is to allow things like:
Currently one can write:
The proposal is that one can also supply behaviour:
The
with
is needed to disambiguate with collection/object initializers. Inside thewith
block,public
visibility is the default.This is not limited to anonymous types. Existing types can be augmented:
Under the covers, this will generate a new type. Obviously the type specified needs to be unsealed/not a value type.
Additional interfaces can be implemented:
Anonymous types can also implement interfaces:
The
with
keyword is optional if the type specified is an interface, as there is no ambiguity with collection/object initializers, which gives the syntax used in the original example.The last variation is a type with only behaviour, no interfaces or state.
Here
with
is required.The text was updated successfully, but these errors were encountered: