I don’t know how to describe it better so that the name can be a little confusing.
I would like to know if it is possible to instantiate a class using ... = new MyClass()and call non-static methods of this class instantly when instantiating?
For example, something like this:
return new MyClass().SetName("some name");
I suppose I have seen something similar before, but I cannot find it. It is a little annoying to do something like ...
MyClass myclass = new MyClass();
myclass.SetName("some name");
return myclass;
Is there a way to shorten it or do it like my first example? (Please do not suggest me using a property instead SetName(string)- this is just an example)
Thanks in advance!
source
share