0
in c# what is different btween using(){} and instance class or object
2 Réponses
+ 1
the curly braces mark the begin and the end on a block of code.
Example : public class Example{ }, public void method(){ }.
The round Parentheses for a method are for the input of the function/procedure.
Example : public String blend(String apples) { return "juice"; }
Also every class has special method named the constructor, thus it has the round parentheses.
The instance of a class is the same thing as the object of that type of class.
The object is the baby of a class :).
+ 1
You cannot compare these two because they are used in totally different things.
Using is used to define a the scope of a object.
Aobject MyObject = new Aobject; Creates a object.
They can be used together. Or create a instance of a class is used without the using.
What a minute, maybe I did not understand your question correct. Did you mean ?
What is de diffence between
using (Aobject MyObject = new Aobject){}
and
Aobject MyObject = new Aobject;
Functional there is no difference.
practical you only use Aobject MyObject = new Aobject; because the garbage collect in c# does all the work for you.
Cosmetical you could use using all because the time to make sure that every object you create is disposed.
ok now serious
I only use using(){} it if the object does anything with external resources like files or databases.