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

  • SEARCH
  • Home
  • 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 7850345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:49:01+00:00 2026-06-02T18:49:01+00:00

I have a little problem, I can’t modify property of structure that is stored

  • 0

I have a little problem, I can’t modify property of structure that is stored in another property and I have no idea why:

Code:

    public struct InfoProTile
    {
        public string Nazev { get; set; }
        public double Hodnota { get; set; }
        public TypValue TypValue { get; set; }
        public NavigovatNa NavigovatNa { get; set; }
    }

        public InfoProTile BNDTileInfo { get { return bndTileInfo; } set { bndTileInfo = value; } } private InfoProTile bndTileInfo;

        LoadModel()
    {
        ...
        BNDTileInfo = new InfoProTile();
        BNDTileInfo.NavigovatNa = NavigovatNa.MainPage;
    }

Error:

Error: Error 3 Cannot modify the return value of '...ViewModel.TilesModel.BNDTileInfo' because it is not a variable

I don’t get it because if I just change it into:

bndTileInfo.NavigovatNa = NavigovatNa.MainPage;

It works. Can anyone please explain it to me?

  • 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-02T18:49:03+00:00Added an answer on June 2, 2026 at 6:49 pm

    A struct is a value type, thus when you access it from a property, you are getting back a copy of the struct and not the underlying field direclty. Thus, C# won’t let you modify that copy of the struct because that is just a temporary object that will be discarded.

    So, when you call:

    BNDTitleInfo.NavigovatNa = ...;
    

    It first calls the get on the property and returns a copy of bndTitleInfo, and then attempts to set the NavigovatNa property and the copy. C# gives you the error here because that is not something you really want to do and thus is protecting you from yourself.

    But, when you call:

    bndTitleInfo.NavigovatNa = ...;
    

    You are referencing the field directly and thus no copy is made and there is no compiler issue.

    The long and the short of it is that mutable value types don’t make good properties (and in general you should avoid mutable value types completely).

    To rectify, you can either make it a reference type (class) or you can make your struct immutable, which would mean you’d have to assign a whole new struct instance to change it’s value.

    If you look at MSDN’s recommendations, in general struct is best suited to small, logical-single-value, immutable constructs: Choosing Between Classes and Structures

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

Sidebar

Related Questions

I have a little problem with autoconf, I know that you can use configure.ac
I have a little problem and I'm hopping that you can help me solve
I have a little problem, I hope U can help me;) Trouble is, that
I have a little problem that perhaps you can help me with. I try
I have little problem in my iPhone application code but can not identify. please
Evening :) I have a little problem... As you can see in my code
I have a little problem and hope that you can help me. I want
I have a little problem that I can't figure out how to solve. I
I have a little problem that is troubling me. Can i connect to a
i have a little problem, i'm searching, but i can't found what i need,

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.