c# - How is "using" statement supposed to work? -


I am trying to take advantage of the statement using in the following code: Uri Uri = new Uri ("http: // localhost: 50222 / odta"); Var Container = New Course System. Container (Yuri); CourseServiceRef.NotNeededededededTempUser = New coursecaref.noted () {email = model. Username, Username 1 = Model User name}; Container.AddToNotNeededs (newTempUser); Container.SaveChanges ();

Although it does not compile. Why?

- does not match - for those objects that implement it so that they can block the code Automatically resolved at the end of:

 using  (var toto = new MyDisposableClass ()) {// do stuff}   

if any This interface of your classes implements the interface (or whatever it happens), you can use the syntax above to call the disposable () method. You can use this int Can not use the use blocks for objects that do not apply the ruffs, it will not be compiled simply.

Basically it will be like the following:

  var toto = New MyDisposableClass (try) {// do stuff} Finally (if (toto! = Null) (( IDisposable) toto) Dissociate ();}   

The only difference here is that in the first scenario, using the toto scope of using The end of the block dies.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -