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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:35:39+00:00 2026-06-14T23:35:39+00:00

i have a structure defined, which contains a public field and a public property

  • 0

i have a structure defined, which contains a public field and a public property named _one and One respectively, now i instantiate the struct in the main function (not creating new object), and called the Property from the struct, i am getting the compile time error saying use of unassigned local variable One, however when i called the field _one, it works pretty expected here what i am doing:

 public struct myStruct
    {
        public int _one;
        public int One
        {
            get { return _one; }
            set { _one = value; }
        }
        public void Display()
        {
            Console.WriteLine(One);
        }
    }



static void Main(string[] args)
        {

            myStruct _struct;
            _struct.One = 2; // Does not works
            _struct._one = 2; // Works fine
        }

can anyone explain whats the reason behind this, could not understand the concept.

  • 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-14T23:35:40+00:00Added an answer on June 14, 2026 at 11:35 pm

    You need to initialize the struct in order for the property to be accessible – _struct has a default value otherwise:

    myStruct _struct = new myStruct(); 
    

    By the way – mutable value types are evil.

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

Sidebar

Related Questions

I have defined a simple private class named SetOb which contains an int and
I have a structure which aims at storing user defined data (i.e. from a
I have a data structure defined as struct myDataStruct { int32_t header; int16_t data[8];
Say I have a Group data structure which contains a list of Element objects,
I have a complex regex, which contains constructs like this one: ( + sectionPattern
I have a data table that contains data which is technically a tree structure,
I am having a struct defined in C++ which contains int and std::string arrays
I have defined a struct in C# to mirror a native data structure and
I have a database structure that has a Person table which contains fields such
I have created a JSF 2 page which uses Facelets to define the structure

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.