Here are few inputs to help you further dissect the problem.
Current:
namespace AskYourQuestion
{
public struct QuestionNum
{
public string Q1;
}
class Questions
{
QuestionNum pq = new QuestionNum();
// pq.Q1 = "hi"; --> This will not work
// Why? See below
}
}
Class is a specification where we encapsulate the members it should hold.
Here the Questions
class encapsulate a member pq
of type QuestionNum
and we should specify on how the Questions
class and it's encapsulating members would be constructed.
Different ways to do this:
- Default it:
QuestionNum pq = new QuestionNum() { Q1 = "Hi" };
- Construct it:
public Questions(string defaultValue) { this.pq.Q1 =
defaultValue; }
- Methods / setters
Examples for each:
Default it:
namespace AskYourQuestion
{
public struct QuestionNum
{
public string Q1;
}
class Questions
{
internal QuestionNum pq = new QuestionNum() { Q1 = "Hi" };
}
}
Construct it:
namespace AskYourQuestion
{
public struct QuestionNum
{
public string Q1;
}
class Questions
{
internal QuestionNum pq = new QuestionNum() { Q1 = "Hi" };
public Questions()
{
}
public Questions(string defaultValue)
{
this.pq.Q1 = defaultValue;
}
}
}
To use it:
Questions quest = new Questions("World");
Console.WriteLine(quest.pq.Q1);
There are many other ways, but you need to choose the best case based on your problem.