for example, I’m trying to initialize a new Person
var me = new Person();
but i’m just wondering if it’s possible for that initialization to automatically return a seed?
I’m trying to add it to the constructor but I don’t know how?
public class Person
{
public Person Person(){ return ...}
}
well, that doesn’t really work. Can anyone explain to me why it doesn’t work and if there’s another way to do this?
I can do object initialization, but I’m just wondering if this is possible??
From your comment:
Just add implementation to the parameterless constructor:
When you call
var me = new Person();, thenNamewill already be populated with"Joe".More usages of constructors
If you want to be able to customize the name more quickly, then you could add parameters to that constructor, or add a different constructor that takes parameters:
In the latest .Net, you can also use default values for these parameters to make your code shorter: