Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6973681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:08:21+00:00 2026-05-27T17:08:21+00:00

public class shape { public int x, y; public class triangle { int sides

  • 0
public class shape
{
    public int x, y;

    public class triangle
    {
        int sides = 3;
    }

    public rectangle rect = new rectangle();

    public class rectangle
    {
        int sides = 4;

        public class square
        {
            public string s;
        }
    }
}

shape a = new shape();
a.x = 4;
a.y = 3;
//print(a.triangle.sides) //no such thing
//print(a.rect.sides) //prints 4
shape.rectangle.square d = new shape.rectangle.square();
d.s = "abc";

It’s a somewhat arbitrary example, but it shows the use of nesting class definitions in C# to work like namespaces.

The inner classes can also inherit from the outer ones and the such as well but the namespace like behaviour is the same.

Except where I made it so in “shape” with “public rectangle rect = new rectangle();” the inner classes are not so much part of the outer ones. It’s more like they just all have similar names, for example they could be unstacked and the reworded with underscores “shape_rectangle_square d = new shape_rectangle_square();”.

I was wondering if there were any performance considerations to this, for example in thease situations.

shape.triangle t = new shape.triangle();

List<shape.triangle> triangles = new List<shape.triangle>();

triangles.Add(new shape.triangle());

foreach (shape.triangle t in triangles)

func(new shape.triangle(1, 2, 3), "ted");

vs

shape_triangle t = new shape_triangle();

List<shape_triangle> triangles = new List<shape_triangle>();

triangles.Add(new shape_triangle());

foreach (shape_triangle t in triangles)

func(new shape_triangle(1, 2, 3), "ted");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:08:22+00:00Added an answer on May 27, 2026 at 5:08 pm

    I was wondering if there were any performance considerations to this?

    No. It could matter a few nanoseconds in compile-time maybe.

    A class allows nested Types. This is sometimes used for (private) ‘helper’ classes and strongly related enums. But it is about structure and organization, not about performance.

    In general, public nested classes are best avoided. Public enums are sligtly more common.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class Order { static Customer cust = new Customer(); string sEmpty = ;
let say i have following class: class Shape { public int widht; public List<Point>
I created three classes: Shape (base class) , Rectangle and Square . I tried
public class Shape{ public int xPos = 10; public int yPos = 20; Shape(){
I have a class as follows: public class Polygon extends Shape{ private int noSides;
I am trying to run the following simple code, public abstract class Shape{ abstract
public class TestBL { public static void AddFolder(string folderName) { using (var ts =
public class Ex7 { private int fld; private void meth(int val) { fld =
public class Test extends Thread{ public void hello(String s){ System.out.println(s); } public void run(){
public static final int SQUARE = 0, LINE = 1, S_FIGURE = 2, Z_FIGURE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.