S
S
Smilley2015-11-10 18:29:48
Programming
Smilley, 2015-11-10 18:29:48

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;

Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sumor, 2015-11-10
@Smilley

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;
            }
        }
    }
}

G
GavriKos, 2015-11-10
@GavriKos

public class Reply
{
public Date Date;
}

public class Appeal
{
public Reply Reply;
}

S
Smilleey, 2015-11-10
@Smilleey

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;
            }
        }
    }
}

But this code throws an error -
An object reference is required for the non-static field, method, or property 'ABtestMethod()' and
'B': cannot reference a type through an expression; try 'AB' instead

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question