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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:12:45+00:00 2026-06-18T02:12:45+00:00

Hi I was using C# Object Initializer like public class Invoice { public decimal

  • 0

Hi I was using C# Object Initializer like

public class Invoice
    {
        public decimal GrossSum { get; set; }
        public decimal GrossSumComp { get; set; }
    }
    public class ABC()
    {
        public Invoice Invoice {get;set;}

        public ABC(decimal grossSum)
        {
            Invoice=new Invoice()
            {
                GrossSum=grossSum,
                GrossSumComp=**GrossSum**
            };
        }
    }

And I saw we can’t assign value of One Property to another in it , Like above I tried to assign GrossSum to GrossSumComp and there I got Compilation error. Just curious to know Why It dont allow this. Any help will be highly apericaited.

  • 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-06-18T02:12:46+00:00Added an answer on June 18, 2026 at 2:12 am

    Because that’s how it’s specified. GrossSum in the second line is a reference to a variable named GrossSum not a property of the object being initialized.

    To paraphrase Eric Lippert. For a feature to be implemented it has do be

    • Proposed
    • Analysed
    • Designed
    • Implemented
    • Tested

    Those all incur a cost, so they should add value to match the cost and preferably exceed the cost.

    If there’s a simple work around to the feature, odds are that the cost is likely to be (a lot) higher than the potential value.

    In your case you can simply assign grossSum instead of GrossSum. That’s a simple work around

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class Like public class Person { public string Name{ get; set;
Using the C# object initializer syntax I can instantiate an anonymous object like this:
Im using StructureMap for IoC, im getting Configuration from App.Config, like this: public class
I have an object model somewhat like this: public class MyObject { public string
When I try to initialize an object using the Object Initializer, ReSharper always inserts
I'm using object and collection Initializers in the program and thinking how to get
I have lots of repositories like this: public class PersonRepository : IPersonRepository { private
I have an Object called CAR declared as follows: public class Car{ public int
I have a class like this: public class LocalizedDataAnnotationsModelMetadataProvider : DataAnnotationsModelMetadataProvider { protected override
Assume I have a class like this: public class Foo { public Bar RequiredProperty

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.