.NET Nested Classes

后端 未结 3 743
粉色の甜心
粉色の甜心 2021-01-24 07:25

The current class library I am working on will have a base class (Field) with over 50 specific \"field\" types which will inherit from \"Field\" and nested for maintain readabil

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-24 08:01

    Sounds like you wanted something like:

    abstract class Field
    {
        public int Length { get; set; }
    }
    
    public class FieldA : Field
    {
        public static void DoSomething()
        {
            Console.WriteLine("Did something.");
        }
    }
    

    Otherwise you're defining a base class with an inner class in it, which inheritorrs will also get. So when you inherit from the outer class to make the inner class, you're starting a loop.

提交回复
热议问题