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 4005876
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:26:49+00:00 2026-05-20T08:26:49+00:00

Hi I was wondering if there is any difference between initializing object like this

  • 0

Hi
I was wondering if there is any difference between initializing object like this

MyClass calass = new MyClass()
{
  firstProperty = "text",
  secondProperty = "text"
}

and initializaing object like this

MyClass calass = new MyClass   // no brackets
{
  firstProperty = "text",
  secondProperty = "text"
}

I was also wondering what is the name of this kind of initialization

  • 1 1 Answer
  • 3 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-20T08:26:50+00:00Added an answer on May 20, 2026 at 8:26 am

    Nope, absolutely no difference. In both cases you’re using an object initializer expression. Object initializers were introduced in C# 3.

    In both cases, this is exactly equivalent to:

    // tmp is a hidden variable, effectively. You don't get to see it.
    MyClass tmp = new MyClass(); 
    tmp.firstProperty = "text";
    tmp.secondProperty = "text";
    
    // This is your "real" variable
    MyClass calass = tmp;
    

    Note how the assignment to calass only happens after the properties have been assigned – just as you’d expect from the source code. (In some cases I believe the C# compiler can effectively remove the extra variable and rearrange the assignments, but it has to observably behave like this translation. It can certainly make a difference if you’re reassigning an existing variable.)

    EDIT: Slight subtle point about omitting constructor arguments. If you do so, it’s always equivalent to including an empty argument list – but that’s not the same as being equivalent to calling the parameterless constructor. For example, there can be optional parameters, or parameter arrays:

    using System;
    class Test
    {
        int y;
    
        Test(int x = 0)
        {
            Console.WriteLine(x);
        }
    
        static void Main()
        {
            // This is still okay, even though there's no geniune parameterless
            // constructor
            Test t = new Test
            {
                y = 10
            };
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if there are any difference between function __construct() { parent::__construct(); $this->load->
I was just wondering if there is any difference between the two different new
Recently I've been wondering if there is any significant difference between this code: public
I was wondering if there was any difference between the MySQL PREPARE/EXECUTE clauses and
i was wondering if there is any significant difference between consuming .asmx services with
I was wondering if there was any performance difference between the two approaches below.
I'm wondering if there's any difference between the code fragment from urllib import request
I am wondering if there is any difference in runtime between a generic container
I was wondering if there are any problems or difference between sending normal headers
I am wondering whether there is any difference between inlining functions on a linker

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.