Answer the question
In order to leave comments, you need to log in
How to work with nested classes?
Good evening. I am developing a class that can have up to 500 fields. I would like to arrange the fields by semantic load for ease of naming and access. What is meant is the top level Appeal class, which includes subclasses Reply, Reviewal, Expertise and others, including their own fields.
Please tell me how to make it so that you can access data in a similar form:
Appeal appeal new Appeal();
repdate = appeal.Reply.Date;
Answer the question
In order to leave comments, you need to log in
Made corrections to your code.
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
A test = new A();
Console.WriteLine(test.bPart.testMethod());
Console.ReadLine();
}
}
class A
{
public B bPart = new B();
public class B
{
private string testB = "I'm test in class B";
public string testMethod ()
{
return testB;
}
}
}
}
public class Reply
{
public Date Date;
}
public class Appeal
{
public Reply Reply;
}
I would like something like this:
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
A test = new A();
Console.WriteLine(test.B.testMethod());
Console.ReadLine();
}
}
class A
{
public class B
{
private string testB = "I'm test in class B";
public string testMethod ()
{
return testB;
}
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question