Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6690493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:38:36+00:00 2026-05-26T05:38:36+00:00

for example, I’m trying to initialize a new Person var me = new Person();

  • 0

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??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:38:37+00:00Added an answer on May 26, 2026 at 5:38 am

    From your comment:

    automatically adds value to the variable (in this case “me”) and populating the instantiated object.. ie: having Person.Name = “Joe” and etc… without me manually doing object initialization or what not… basically I want the model/class to create its own data right after I instantiate it..

    Just add implementation to the parameterless constructor:

    public class Person
    {
        public Person()
        {
            this.Name = "Joe";
        }
    
        public string Name { get; set; }
    }
    

    When you call var me = new Person();, then Name will 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:

    public class Person
    {
        public Person()
            : this("Joe") // Calls the other constructor that takes a name...
        {
        }
    
        public Person(string name)
        {
            this.Name = name;
        }
    
        public string Name { get; set; }
    }
    
    var me = new Person(); // Joe
    var you = new Person("You");
    

    In the latest .Net, you can also use default values for these parameters to make your code shorter:

    public class Person
    {
        public Person(string name = "Joe") // Will be "Joe" unless you say otherwise
        {
            this.Name = name;
        }
    
        public string Name { get; set; }
    }
    
    var me = new Person(); // Joe
    var you = new Person("You");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Example: var sessions = require('sessions'); function load_session(req) { sessions.load(sid); } Now that the session
Example I have Person , SpecialPerson , and User . Person and SpecialPerson are
Example: find / * Gives me all files and directories, but I want only
Example class code: <?php class example { public function forExample() { return true; }
Example: error_reporting(E_ALL | E_STRICT); class Test {} $obj = new Test(); $obj->undeclared = oops;
Example Outlook: its only one process but can have multiple windows (user can double
Example of strings to search: name = 'bob' person=mary init= 'tim', first =sarah, ,name=o'donnel
Example: This is just\na simple sentence . I want to match every character between
Example: Foo make_foo(int a1, int a2){ Foo f(a1,a2); return f; } Having seen such
Example, I want to specialize a class to have a member variable that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.