static void Main(string[] args)
{
foo f1 = new foo();
string s1 = f1.fooMethod();
string s2 = (new foo()).fooMethod();
}
class foo
{
public string fooMethod()
{
return "fooMethod called";
}
}
in the above code, I created an anonymous object using the syntax (new foo())(I assume this is what these objects are called) and one object f1.
Now f1available in the entire code block, but the anonymous object is not (of course). Questions:
- Is this anonymous object destroyed on the next line as soon as the work is done?
- Is this way of creating anonymous objects good or bad compared to creating an object
f1(especially when we need to call only one method of this class, as in this case)?
source
share