KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have one observation about struct. When I declare a property in Struct and if I don't initialize the Struct then it gives me the below error - "Use of unassigned local variable empStruct" PSeduo Code- struct EmpStruct { private int firstNumber; public int FirstNumber { get { return firstNumber; } set { firstNumber = value; } } public int SecondNumber; } Program.cs- EmpStruct empStruct; empStruct.FirstNumber = 5; But when I declare public variable then the above code works. EmpStruct empStruct; empStruct.SecondNumber; So my question is why compiler not gives error when i try to access variable.(In case of Class it will give the error).
Tags (comma-separated)
Save Edits
Cancel