The Objects of a Project

Introduction

When it comes to a computer application, an object is anything that participates in a program. It can be a file, a symbol, something to click, something to select, etc. An object is created from a type. The C# language supports many types (interfaces, classes (with many variations involving inheritance), records, structures, and enumerations), the .NET Framework provides various options, and Microsoft Visual Studio offers many tools.

Practical LearningPractical Learning: Introducing Objects

  1. Start Microsoft Visual Studio
  2. In the Visual Studio 2026 dialog box, click Create A New Project
  3. In the Languages combo box of the Create A New Project dialog box, select C# and, in the list of projects templates, click Console App.
    Click Next
  4. In the Configure Your New Project wizard page, change the Solution Name to Geometry
  5. Change the Project Name to Polygonals
  6. Click Next
  7. In the Additional Information wizard page, in the Framework combo box, select the highest version.
    Click Create
  8. In the Solution Explorer, right-click Program.cs -> Rename
  9. Type Evaluations (to get Evaluations.cs) and press Enter
  10. Click Create

An Interface

An interface is the most fundamental description of an object. An interface is usually small to perform one precise operation or a limited number of operations. An interface is used to serve other types but an interface can also implement one or more interfaces.

Practical LearningPractical Learning: Creating Interfaces

  1. To create an interface, in the Solution Explorer, right-click Polygonals -> Add -> Class...
  2. In the middle list of the Add New Item dialog box, click Interface
  3. Change the file Name to IDescription
  4. Click Add
  5. Change the document as follows:
    namespace Polygonals
    {
        internal interface IDescription
        {
            public abstract void Describe();
        }
    }
  6. To create another interface, in the Solution Explorer, right-click Polygonals -> Add -> Class...
  7. In the middle list of the Add New Item dialog box, click Interface
  8. Change the file Name to IPolygon
  9. Click Add
  10. Change the document as follows:
    namespace Polygonals
    {
        internal interface IPolygon : IDescription
        {
            abstract int    Sides                { get; }
            abstract double Side                 { get; set; }
            abstract int    InternalAngle        { get; }
            abstract int    SumOfInterriorAngles { get; }
            abstract double CalculatePerimeter();
            abstract double CalculateArea();
            abstract double CalculateInscribedRadius();
            abstract double CalculateCircumscribedRradius();
        }
    }

The Type of an Object

Many computer languages, especially compilation-based languages (C++, (Object) Pascal, C#, Visual Basic, F#, etc) provides various types to let you to create obfects. Options include classes, structures, records, enumerations, etc. A class is the most common type used to create an object.

Practical LearningPractical Learning: Creating Classes

  1. To create a class, in the Solution Explorer, right-click Polygonals -> Add -> Class...
  2. Change the file Name to Pentagon
  3. Click Add
  4. Change the document as follows:
    namespace Polygonals
    {
        internal class Pentagon : IPolygon, IDescription
        {
            public int Sides
            {
                get
                {
                    return 5;
                }
            }
    
            public double Side { get; set; }
    
            public int InternalAngle
            {
                get
                {
                    return 108;
                }
            }
    
            public virtual int SumOfInterriorAngles
            {
                get
                {
                    return 540;
                }
            }
    
            public virtual double CalculatePerimeter()
            {
                return Side * Sides;
            }
    
            public virtual double CalculateArea()
            {
                return Side * Side * Math.Sqrt(5.00 * (5.00 + (2.00 * Math.Sqrt(5.00)))) / 4.00;
            }
    
            public double CalculateInscribedRadius()
            {
                // http://mathworld.wolfram.com/Pentagon.html
                return Side * Math.Sqrt(25.00 + (10.00 * Math.Sqrt(5.00))) / 10.00;
    
                // https://en.wikipedia.org/wiki/Pentagon
                // return Side / (2.00 * Math.Sqrt(5.00 - Math.Sqrt(20.00)));
            }
    
            public double CalculateCircumscribedRradius()
            {
                // http://mathworld.wolfram.com/Pentagon.html
                return Side * Math.Sqrt(50.00 + (10.00 * Math.Sqrt(5.00))) / 10.00;
            }
    
            public virtual void Describe()
            {
                Console.WriteLine("Pentagon Characteristics");
                Console.WriteLine("-------------------------------------------");
                Console.WriteLine("Side:                    {0}", Side);
                Console.WriteLine("Number of Sides:         {0}", Sides);
                Console.WriteLine("Internal Angle:          {0}", InternalAngle);
                Console.WriteLine("Sum of Interrior Angles: {0}", SumOfInterriorAngles);
                Console.WriteLine("-------------------------------------------");
                Console.WriteLine("Perimeter:               {0}", CalculatePerimeter());
                Console.WriteLine("Inscribed Radius:        {0}", CalculateInscribedRadius());
                Console.WriteLine("Circumscribed Rradius:   {0}", CalculateCircumscribedRradius());
                Console.WriteLine("Area:                    {0}", CalculateArea());
                Console.WriteLine("===========================================");
            }
        }
    
        public record Quadrilateral
        {
        
        }
    }
    
  5. To create another class, on the main menu, click Project and click Add Class...
  6. Change the file Name to Triangle
  7. Click Add
  8. Change the document as follows:
    namespace Polygonals
    {
        internal class EquilateralTriangle : IPolygon, IDescription
        {
            public int Sides
            {
                get
                {
                    return 3;
                }
            }
    
            public double Side { get; set; }
    
            public virtual int InternalAngle
            {
                get
                {
                    return 60;
                }
            }
    
            public virtual int SumOfInterriorAngles
            {
                get
                {
                    return 180;
                }
            }
    
            public virtual double CalculatePerimeter()
            {
                return Side * Sides;
            }
    
            public virtual double CalculateArea()
            {
                return Side * Side * Math.Sqrt(3.00) / 4.00;
            }
    
            public virtual double CalculateInscribedRadius()
            {
                return Side * Math.Sqrt(3.00) / 6.00;
            }
    
            public virtual double CalculateCircumscribedRradius()
            {
                return Side * Math.Sqrt(3.00);
            }
    
            public double CalculateAltitude()
            {
                return (Math.Sqrt(3.00) / 2.00) *Side;
            }
    
            public virtual void Describe()
            {
                Console.WriteLine("Equilateral Triangle Characteristics");
                Console.WriteLine("-------------------------------------------");
                Console.WriteLine("Side:                    {0}", Side);
                Console.WriteLine("Number of Sides:         {0}", Sides);
                Console.WriteLine("Internal Angle:          {0}", InternalAngle);
                Console.WriteLine("Sum of Interrior Angles: {0}", SumOfInterriorAngles);
                Console.WriteLine("-------------------------------------------");
                Console.WriteLine("Altitude:                {0}", CalculateAltitude());
                Console.WriteLine("Inscribed Radius:        {0}", CalculateInscribedRadius());
                Console.WriteLine("Circumscribed Rradius:   {0}", CalculateCircumscribedRradius());
                Console.WriteLine("Perimeter:               {0}", CalculatePerimeter());
                Console.WriteLine("Area:                    {0}", CalculateArea());
                Console.WriteLine("===========================================");
            }
        }
    }
  9. To create another class, in the Solution Explorer, right-click Polygonals -> Add -> Class...
  10. In the middle list of the Add New Item dialog box, make sure Class is selected.
    Change the file Name to Square
  11. Click Add
  12. Change the document as follows:
    namespace Polygonals
    {
        internal record Square : IPolygon, IDescription
        {
            public double Side { get; set; }
    
            public virtual int Sides
            {
                get
                {
                    return 4;
                }
            }
    
            public int InternalAngle
            {
                get
                {
                    return 90;
                }
            }
    
            public virtual int SumOfInterriorAngles
            {
                get
                {
                    return 360;
                }
            }
    
            public virtual double CalculatePerimeter()
            {
                return Side * Sides;
            }
    
            public virtual double CalculateArea()
            {
                return Side * Side;
            }
    
            public double CalculateInscribedRadius()
            {
                return Side / 2.00;
            }
    
            public double CalculateCircumscribedRradius()
            {
                return (1.00 / Math.Sqrt(2.00)) * Side;
            }
    
            public virtual void Describe()
            {
                Console.WriteLine("Square Characteristics");
                Console.WriteLine("-------------------------------------------");
                Console.WriteLine("Side:                    {0}", Side);
                Console.WriteLine("Number of Sides:         {0}", Sides);
                Console.WriteLine("Internal Angle:          {0}", InternalAngle);
                Console.WriteLine("Sum of Interrior Angles: {0}", SumOfInterriorAngles);
                Console.WriteLine("-------------------------------------------");
                Console.WriteLine("Inscribed Radius:        {0}", CalculateInscribedRadius());
                Console.WriteLine("Circumscribed Rradius:   {0}", CalculateCircumscribedRradius());
                Console.WriteLine("Perimeter:               {0}", CalculatePerimeter());
                Console.WriteLine("Area:                    {0}", CalculateArea());
                Console.WriteLine("===========================================");
            }
        }
    
        public record Rhombus : Quadrilateral
        {
            public double Width  { get; set; }
            public double Height { get; set; }
        }
    }
  13. Click the Evaluations.cs tab to access the primary document of the project and change it as follows:
    using Polygonals;
    using static System.Console;
    
    Square sqr               = new Square();
    Rhombus rho              = new Rhombus();
    IPolygon pent            = new Pentagon();
    EquilateralTriangle tri  = new EquilateralTriangle();
    
    sqr.Side      = 227.93;
    tri.Side      = 227.93;
    pent.Side     = 227.93;
    
    WriteLine("===========================================");
    WriteLine("Geometry");
    WriteLine("===========================================");
    
    tri.Describe();
    sqr.Describe();
    pent.Describe();
    
    rho.Width  = 927.58;
    rho.Height = 1377.93;
    
    WriteLine("Rhombus Characteristics");
    WriteLine("-------------------------------------------");
    WriteLine("Width:                    {0}", rho.Width);
    WriteLine("Height:                   {0}", rho.Height);
    WriteLine("===========================================");
  14. To execute the application, on the main menu, click Debug -> Start Without Debugging:
    ===========================================
    Geometry
    ===========================================
    Equilateral Triangle Characteristics
    -------------------------------------------
    Side:                    227.93
    Number of Sides:         3
    Internal Angle:          60
    Sum of Interrior Angles: 180
    -------------------------------------------
    Altitude:                197.3931702845871
    Inscribed Radius:        65.7977234281957
    Circumscribed Rradius:   394.7863405691742
    Perimeter:               683.79
    Area:                    22495.91265148297
    ===========================================
    Square Characteristics
    -------------------------------------------
    Side:                    227.93
    Number of Sides:         4
    Internal Angle:          90
    Sum of Interrior Angles: 360
    -------------------------------------------
    Inscribed Radius:        113.965
    Circumscribed Rradius:   161.17084863584978
    Perimeter:               911.72
    Area:                    51952.0849
    ===========================================
    Pentagon Characteristics
    -------------------------------------------
    Side:                    227.93
    Number of Sides:         5
    Internal Angle:          108
    Sum of Interrior Angles: 540
    -------------------------------------------
    Perimeter:               1139.65
    Inscribed Radius:        156.85936556649727
    Circumscribed Rradius:   193.8888387476805
    Area:                    89382.38798392932
    ===========================================
    Rhombus Characteristics
    -------------------------------------------
    Width:                    927.58
    Height:                   1377.93
    ===========================================
    
    Press any key to close this window . . .
  15. In the DOS window, press U to close the window and return to your programming environment

Accessing the Code of a Project

Introduction

If you have a project with various files, objects accessed from different files, functions and methods called from various places, it can be overwhelming to find a piece or section of code you are looking for. Fortunately, Microsoft Visual Studio provides various tools to assist you.

Accessing the References to a Type

After creating a type (interface, class, record, or structure) and using it in various places (such as creating objects), at one time, you may want to know all the places where the object is used. Instead of performing that operation manually, Microsoft Visual Studio can assist you. To start, where the type is created, check the line above it. You can click that string and use the menu that would come up.

Practical LearningPractical Learning: Accessing the References to a Property or Method

  1. Click the IDescription.cs tab to access that interface.
    Notice the line above it that displays "4 references"
  2. Above the "internal interface IDescription" line, click "4 references" and notice the menu that comes up
  3. Position the mouse on the first IDescription, then move the mouse to the second IDescription and double-click
  4. Click the Triangle.cs tab to access a class.
    Above the "internal class Triangle : IPolygon, IDescription" line, notice the line that displays "2 references"
  5. Above the "internal class Triangle : IPolygon, IDescription" line, click "2 references" and notice the menu that comes up
  6. Position the mouse on the first "Triangle tri = new Triangle();", then move the mouse to the second "Triangle et = new Triangle();" and double-click

Accessing the References to a Property or Method

After creating a property and accessing it in one or more places, after defining a function or a method and calling it in one or more places, you may want to get a list of all the places where the property is accessed or where the function or method is called. Microsoft Visual Studio can help you get that information.

Practical LearningPractical Learning: Accessing the References to a Property or Method

  1. Click the IDescription.cs tab to access that interface.
    Notice the line above "public abstract void Describe();" that displays "6 references"
  2. Click "6 references".
    In the menu that appears, position the mouse on "public virtual void Describe()" and notice the code window that displays on the right side
  3. Double-click the "public virtual void Describe()"
  4. Click the Square.cs tab to access a class.
    Notice the line above "public virtual int SumOfInterriorAngles" that displays "2 references"
  5. Above the "public virtual int SumOfInterriorAngles" line, click "2 references" and notice the menu that comes up
  6. Position the mouse on the first menu option and double-click

Accessing the Definition of an Item

Sometimes, when viewing a variable, an object, a property, a function call, or a method call in your code, you may not know or don't remember how that variable was declared, how that object was created, or how the function or method was defined. Instead of manually tracking such a definition, Microsoft Visual Studio can assist you. If you right-click a variable or an object in the Code Editor, you can then click Go To Definition. The studio would jump to the area where the variable is declared or where the object is created. If you right-click a function or a method call, the studio would present the area where the function or the method is defined.

Practical LearningPractical Learning: Accessing the References to a Property or Method

  1. Click the Evaluations.cs tab to access the primary file of the project.
    Notice how the variables are declared:
    Square sqr               = new Square();
    Rhombus rho              = new Rhombus();
    IPolygon pent            = new Pentagon();
    EquilateralTriangle tri  = new EquilateralTriangle();
    
    sqr.Side      = 227.93; 
    tri.Side      = 227.93;
    pent.Side     = 227.93;
  2. Right-click the first Side and click Go To Definition.
    Notice that the Square.cs document displays and the focus is on the Side property
  3. Click the Evaluations.cs tab again to access the primary file of the project
  4. To locate the creation of a type, in the document, right-click Rhombus on the "Rhombus rho = new Rhombus();" line and click Go To Definition.
    Notice that the Square.cs document is displayed and the focus is on the start of the Rhombus record
  5. To locate a parent type, in the document, right-click Quadrilateral and click Go To Definition.
    Notice that the Pentagon.cs document is displayed and the focus moves to the bottom Rhombus record

Peeking a Definition of a Property or Method

As you might have noticed from the previous section, the Go To Definition requires that you access a property or a method in the file where it is defined. In fact, that technique displays the whole file, which is very useful sometimes. Sometimes, you just want to see, briefly, that piece of code. Microsoft Visual Studio can assist you with the Peek Definition option.

Practical LearningPractical Learning: Peeking a Definition of a Property or Method

  1. Click the Evaluations.cs tab to access the primary document of the project
  2. In the document, on the "pent.Describe();" line, to take a peek at where the object was instantiated, right-click pent and click Peek Definition
  3. To close the Peek Definition window, click its Close button
  4. In the document, on the "pent.Describe();" line, to take a peek at where the method was defined, right-click the Describe() method call and click Peek Definition
  5. In the document, on the "tri.Describe();" line, right-click the Describe() method call and click Peek Definition
  6. To create another class, on the main menu, click Project and click Add Class...
  7. Change the file Name to Hexagon
  8. Click Add
  9. To create another class, on the main menu, click Project and click Add Class...
  10. Change the file Name to Heptagon
  11. Click Add
  12. To create another class, on the main menu, click Project and click Add Class...
  13. Change the file Name to Octagon
  14. Click Add
  15. To create another class, on the main menu, click Project and click Add Class...
  16. Change the file Name to Nonagon
  17. Click Add
  18. To create another class, on the main menu, click Project and click Add Class...
  19. Change the file Name to Decagon
  20. Click Add
  21. To add a project, in the Solution Explorer, right-click Geometry -> Add -> New Project...
  22. Click the arrow of the languages combo box of the Add New Project dialog box and select Visual Basic
  23. Below the languages combo box, make sure Console App is highlighted (if not, click Console App).
    Click Next
  24. Change the Project Name to Volumetrics
  25. Click Next
  26. In the Additional Information wizard page, click Create
  27. To create a class, in the Solution Explorer, right-click Volumetrics -> Add -> Class...
  28. Change the file Name to Square
  29. Click Add
  30. Change the document as follows:
    Public Class Square
        Public Overridable Property Length As Double
    
        Public Overridable Function CalculatePerimeter() As Double
            Return Length * 4.0
        End Function
    
        Public Overridable Function CalculateArea() As Double
            Return Length * Length
        End Function
    
        Public Overridable Sub Describe()
            Console.WriteLine("Square")
            Console.WriteLine("----------------------------------")
            Console.WriteLine("Side:           {0}", Length)
            Console.WriteLine("----------------------------------")
            Console.WriteLine("Perimeter:      {0}", CalculatePerimeter)
            Console.WriteLine("Area:           {0}", CalculateArea)
        End Sub
    End Class
  31. To create an interface, in the Solution Explorer, right-click Volumetrics -> Add -> Class...
  32. Change the file Name to Cube
  33. Click Add
  34. Change the document as follows:
    Public Class Cube
        Inherits Square
    
        Public Function CalculateVolume() As Double
            Return Length * Length * Length
        End Function
    
        Public Overloads Sub Describe()
            Console.WriteLine("Cube")
            Console.WriteLine("==================================")
            Console.WriteLine("Each Face")
            Console.WriteLine("----------------------------------")
            Console.WriteLine("Side:           {0}", Length)
            Console.WriteLine("Perimeter:      {0}", CalculatePerimeter)
            Console.WriteLine("Area:           {0}", CalculateArea)
            Console.WriteLine("----------------------------------")
            Console.WriteLine("Cube Volume:    {0}", CalculateVolume)
        End Sub
    End Class
  35. To create a class, in the Solution Explorer, right-click Volumetrics -> Add -> Class...
  36. Change the file Name to Rectangle
  37. Click Add
  38. Change the document as follows:
    Public Class Rectangle
        Inherits Square
    
        Public Property Height As Double
    
        Public Overloads Function CalculatePerimeter() As Double
            Return (Length + Height) * 2.0
        End Function
    
        Public Overloads Function CalculateArea() As Double
            Return Length * Height
        End Function
    
        Public Overloads Sub Describe()
            Console.WriteLine("Rectangle")
            Console.WriteLine("----------------------------------")
            Console.WriteLine("Length:         {0}", Length)
            Console.WriteLine("Height:         {0}", Height)
            Console.WriteLine("----------------------------------")
            Console.WriteLine("Perimeter:      {0}", CalculatePerimeter)
            Console.WriteLine("Area:           {0}", CalculateArea)
        End Sub
    End Class
  39. To create a class, in the Solution Explorer, right-click Volumetrics -> Add -> Class...
  40. Change the file Name to Box
  41. Click Add
  42. Change the document as follows:
    Public Class Box
        Inherits Rectangle
    
        Public Property Width As Double
    
        Public Function CalculateLengthHeightPerimeter() As Double
            Return (Length + Height) * 2.0
        End Function
    
        Public Function CalculateLengthWidthPerimeter() As Double
            Return (Length + Width) * 2.0
        End Function
    
        Public Function CalculateHeightWidthPerimeter() As Double
            Return (Height + Width) * 2.0
        End Function
    
        Public Function CalculateLengthHeightArea() As Double
            Return Length * Height
        End Function
    
        Public Function CalculateLengthWidthArea() As Double
            Return Length * Width
        End Function
    
        Public Function CalculateHeightWidthArea() As Double
            Return Height * Width
        End Function
    
        Public Function CalculateVolume() As Double
            Return Length * Height * Width
        End Function
    
        Public Overloads Sub Describe()
            Console.WriteLine("Box")
            Console.WriteLine("==================================")
            Console.WriteLine("Face One")
            Console.WriteLine("----------------------------------")
            Console.WriteLine("Length:         {0}", Length)
            Console.WriteLine("Height:         {0}", Height)
            Console.WriteLine("Perimeter:      {0}", CalculateLengthHeightPerimeter)
            Console.WriteLine("Area:           {0}", CalculateLengthHeightArea)
            Console.WriteLine("==================================")
            Console.WriteLine("Face Two")
            Console.WriteLine("----------------------------------")
            Console.WriteLine("Length:         {0}", Length)
            Console.WriteLine("Width:          {0}", Width)
            Console.WriteLine("Perimeter:      {0}", CalculateLengthWidthPerimeter)
            Console.WriteLine("Area:           {0}", CalculateLengthWidthArea)
            Console.WriteLine("==================================")
            Console.WriteLine("Face Three")
            Console.WriteLine("----------------------------------")
            Console.WriteLine("Height:         {0}", Height)
            Console.WriteLine("Width:          {0}", Width)
            Console.WriteLine("Perimeter:      {0}", CalculateHeightWidthPerimeter)
            Console.WriteLine("Area:           {0}", CalculateHeightWidthArea)
            Console.WriteLine("----------------------------------")
            Console.WriteLine("Box Volume:     {0}", CalculateVolume)
        End Sub
    End Class
  43. To create a class, in the Solution Explorer, right-click Volumetrics -> Add -> Class...
  44. Change the file Name to TriangularPrism
  45. Click Add
  46. To create an interface, in the Solution Explorer, right-click Volumetrics -> Add -> Class...
  47. Change the file Name to PentagonalPrism
  48. Click Add
  49. To create an interface, in the Solution Explorer, right-click Volumetrics -> Add -> Class...
  50. Change the file Name to HexagonalPrism
  51. Click Add
  52. To create an interface, in the Solution Explorer, right-click Volumetrics -> Add -> Class...
  53. In the middle list of the Add New Item dialog box, click Interface
  54. Change the file Name to ICircular
  55. Click Add
  56. To create a class, in the Colution Explorer, right-click Volumetrics and click Add Class...
  57. Change the file Name to Circle
  58. Click Add
  59. To create a class, in the Colution Explorer, right-click Volumetrics and click Add Class...
  60. Change the file Name to Sphere
  61. Click Add
  62. To create a class, in the Colution Explorer, right-click Volumetrics and click Add Class...
  63. Change the file Name to Cone
  64. Click Add
  65. To create a class, in the Colution Explorer, right-click Volumetrics and click Add Class...
  66. Change the file Name to Cylinder
  67. Click Add
  68. To create a class, in the Colution Explorer, right-click Volumetrics and click Add Class...
  69. Change the file Name to Tank
  70. Click Add
  71. In the Solution Explorer, below Volumetrics, right-click Program.vb and click Rename
  72. Replace Program with Preparations (to get Preparations.vb) and press Enter twice to save the file and access it
  73. Change the document as follows:
    Imports System
    
    Module Preparations
        Sub Main(args As String())
            Dim sqr As New Square
            Dim cub As New Cube
            Dim rect As New Rectangle
            Dim bx As New Box
    
            sqr.Length = 579.284
            cub.Length = 579.284
    
            rect.Length = 752.496
            rect.Height = 495.874
    
            bx.Length = 752.496
            bx.Height = 495.874
            bx.Width = 529.337
    
            sqr.Describe()
            Console.WriteLine("==================================")
            cub.Describe()
            Console.WriteLine("##################################")
    
            rect.Describe()
            Console.WriteLine("==================================")
            bx.Describe()
            Console.WriteLine("==================================")
        End Sub
    End Module
  74. To test the Visual Basic project, in the Solution Explorer, right-click Volumetrics -> Debug -> Start Without Debugging:
    Square
    ----------------------------------
    Length:         579.284
    ----------------------------------
    Perimeter:      2317.136
    Area:           335569.952656
    ==================================
    Cube
    ==================================
    Each Face
    ----------------------------------
    Side:           579.284
    Perimeter:      2317.136
    Area:           335569.952656
    ----------------------------------
    Cube Volume:    194390304.45437828
    ##################################
    Rectangle
    ----------------------------------
    Length:         752.496
    Height:         495.874
    ----------------------------------
    Perimeter:      2496.74
    Area:           373143.201504
    ==================================
    Box
    ==================================
    Face One
    ----------------------------------
    Length:         752.496
    Height:         495.874
    Perimeter:      2496.74
    Area:           373143.201504
    ==================================
    Face Two
    ----------------------------------
    Length:         752.496
    Width:          529.337
    Perimeter:      2563.666
    Area:           398323.97515199997
    ==================================
    Face Three
    ----------------------------------
    Height:         495.874
    Width:          529.337
    Perimeter:      2050.422
    Area:           262484.455538
    ----------------------------------
    Box Volume:     197518502.85452285
    ==================================
    
    Press any key to close this window . . .
  75. Press I to close the DOS window and return to your programming environment
  76. To add a project, in the Solution Explorer, right-click Geometry -> Add -> New Project...
  77. Click the arrow of the languages combo box of the Add New Project dialog box and select F#
  78. Below the languages combo box, make sure Console App is highlighted (if not, click Console App).
    Click Next
  79. Change the Project Name to Polyhedrons
  80. Click Next
  81. In the Additional Information wizard page, click Create
  82. In the Solution Explorer, below Polyhedrons, right-click Program.fs and click Rename
  83. Type Structurals (to get Structurals.fs) and press Enter
  84. To start a class, in the Solution Explorer, right-click Polyhedrons -> Add -> New Item...
  85. In the middle list of the Add New Item dialog box, make sure Source File is selected (if not, click it).
    Change the file Name to Octahedron
  86. Click Add
  87. To start a class, in the Solution Explorer, right-click Polyhedrons -> Add -> New Item...
  88. Change the file Name to Hexahedron
  89. Click Add
  90. To start a class, in the Solution Explorer, right-click Polyhedrons -> Add -> New Item...
  91. Change the file Name to Pentahedron
  92. Click Add
  93. To start a class, in the Solution Explorer, right-click Polyhedrons -> Add -> New Item...
  94. Change the file Name to Dodecahedron
  95. Click Add
  96. To start a class, in the Solution Explorer, right-click Polyhedrons -> Add -> New Item...
  97. Change the file Name to Tetrahedron
  98. Click Add

Renaming a Variable

If you have a variable that uses a name you don't like, you can change the name of that variable. If the variable is used only once in your code, you can just highlight it and change its name. If the variable is used in various sections of your project, it is not practical to manually rename every instance of that variable. Fortunately, Microsoft Visual Studio can assist you with that operation. First find the variable. Right-click it and click Rename. A small window would come up. In that window, replace the desired name and press Enter.

Practical LearningPractical Learning: Renaming a Variable

  1. To access one of the files we need, click either the IPolygon.cs tab, the Square.cs tab, the Triangle.cs tab, or the Pentagon.cs tab
  2. In one of those documents, right-click Sides and click Rename
  3. Type Edges as the new name and press Enter

The Files of a Project

Introduction

As you should be aware now, a project is made of many code files. A project can contain dozens, hundreds, or thousands of files. As a solution can contain one project, it can also contain dozens or hundreds of projects. When a solution and its project(s) contain dozens, hundreds, or thousands of files, it can be difficult to locate a file you are looking for. Fortunately, Microsoft Visual Studio provides many tools to assist you.

Opening any File

In previous lessons, we saw how to work on files, including creating various types of files, without first necessarily first creating a project or a solution. Then we saw how to open files, including files of various types. The technique we learned also apply to files that belong to projects.

In previous lessons, we saw that Microsoft Visual Studio keeps a list of files that were previously accessed. Then we saw how to open a file from that list il the File menu of Microsoft Visual Studio.

Accessing a File from the Window Menu Category

As you may know already the main menu of Microsoft Visual Studio includes a Window menu category. We saw that that menu item holds a list of files that are currently opened. Indeed, if you are working on one or more projects of a solution, the Window menu would contain a list of all the files that are currently opened. One of the features of that list is that each item shows the name of its project, the name of the file, and its extension:

By default, the Window menu item displays 10 items. This number is controlled in the Tools window. To change it, on the main menu of Microsoft Visual Studio, click Tools and click Options. Set the desired number in the Items To Show In Window Menu:

Microsoft Visual Studio - Options

To allow you to see other files, the Window menu is equipped with an item titled Windows... As is a convention in Microsoft Windows operating systems, the three periods (...) indicate that if you click that menu item, a window, in this case a dialog box, would open. In this case, the dialog box would display two columns in a list view and a few buttons:

Windows

To open a file, click it and click Activate.

Using the Solution Explorer

One of the easiest ways to open a code file is from the Solution Explorer. To open a file, you can double-click it. As another option, you can right-click the file and click Open. In this case, Microsoft Visual Studio would open the file in the normal Code Editor. Actually, Microsoft Visual Studio includes various editors for different types of files. For example, if you double-click a graphics file, an appropriate window would display it. You can also indicate to Microsoft Visual Studio the type of editor you want it to open a file. To do that, in the Solution Explorer, right-click the desired file and click Open With. A dialog box would display:

Open With

In the Open With dialog box, click the desired editor and click OK.

Navigating among the Files

Introduction

You are probably aware that, when you use a browser to access the Internet, you can access the page you recently visited by clicking the previous button. If you previously visited a page and moved back, you can visit the page that is considered the next one. Microsoft Visual Studio provides the same capability. To make this possible, Microsoft Visual Studio keeps an ordered list of documents that are accessed.

Navigating Backward

To access a document that was just recently used:

Navigating Forward

To access a document that is positioned ahead of the current document:

Navigating by Selection

As you may realize, navigating is limited to the document that was just previously accessed. If you want to navigate something that was far accessed, you have to keep navigating backward or forwoard, one document at a time. Microsoft Visual Studio provides a better visual solution. To use it, press and hold Ctrl. Then press Tab and release while you are still holding Ctrl. This would present a window that contains a list of all the files that are currently opened:

Documents Navigator

While you are still holding Ctrl, keep pressing Tab until the desired file is selected. Then release both Ctrl and Tab. The file that was selected would then display.

Introduction to Documents and their Tabs

Overview

As you should be aware already, every time you create or open a file, Microsoft Visual Studio creates a tab for that file. Microsoft Visual Studio provides many options to manage those tabs.

To manage the tabs:

In both cases, refer to the options in the Tabs section:

Options - Tabs

Accessing a Tab

As you should know by now, to access a document that is represeted with a tab, you can simply click the tab. This action would cause the document to be accessed and displayed. You can then use that document such as simply reading it or editing it.

The Selected Tab and the Solution Explorer

You may already be aware that a project can contain many files, a solution can contain many projects that in turn contain many files, and two or more projects can have files with the same name. By default, when you click a tab to access its file, the Solution Explorer is not aware of the selection. In some (in fact many) cases, when you open a file, you want to know the project to which the file belongs. This can be important if the name of the file can be found in different projects.

When a file is accessed by its tab, you can ask the Solution Explorer to indicate the path to the file. To do this, open the Options window. On the left side, click Projects and Solution. In the right General section, make your decision on the Track Active Item in Solution Explorer.

The Rows of Tabs

When you start a project, Microsoft Visual Studio creates a tab for the first file(s) (some projects start with one file (Console App); some other projects immediately open many files when they start (MVC, Python, etc). Every time you create a file, a tab is added for it. The tabs are added from the left to the right above the Code Editor. The number of tabs depends on the monitor resolution you are using.

Using Multiple Rows of Tabs

When the area allocated to the tabs becomes full, the next new tabs would be added but would be hidden. A solution is to show the tabs in various rows. To make it happen, you have two options:

Practical LearningPractical Learning: Using Multiple Rows of Tabs

  1. On the right side of the tabs above the Code Editor, click the Settings button and click Show Tabs In Multiple Rows

The Positions of Tabs

By default, the tabs display horizontally in the top section of the Code Editor. As an alternative, you can position them to the left or the right side of the Code Editor. You have two options:

Revealing or Hiding Multiple Rows of Tabs

After allowing the Code Editor to show multiple tab, you have the option of showing one row of tabs or multiple rows. To to that, position the mouse on the row of tabs, and roll the mouse wheel.

Accessing an Active File

As you should know now, to access a file, you can click its tab. If you have many files, it can be difficult to find the file you want. As an alternative, you can use the Active Files button Active Files on the tabs above the Code Editor.

Practical LearningPractical Learning: Accessing a Tabbed File

Pinning the Order of Tabs

As mentioned already, if you start working on a project, at least one tab would be created for a file. We saw how to close some tabs. We also saw how to create or open file and get their tabs. If no tab is displaying, if you create a new file or open an existing file, the tab for that file is created. Every time you create a new file or open a file, Microsoft Visual Studio creates a tab for the new file and adds that tab to the right side of the existing tab(s). In other words, the tabs are created in the order their files are added. After opening the tabs, if you close the solution, when you re-open it, Microsoft Visual Studio would remember the files that were opened and the order of their tabs.

If you want, you can indicate the order of files and tabs you want. This is done by pining the tabs in the order of your choice. To pin a tab:

If you have no pinned tab, if you pin a tab, its Pin Tab button would become selected. If there is only one row of tabs, the pinned tab would be moved to the left. If there is more than one row of tabs, the new pinned tab would be moved to the left section of the top tab. If you pin another tab, it would be position to the right of the existing pinned tab(s). You can keep pining the tabs as you want. The tabs that are pinned are positioned from left to right in the order they are pinned. The other tabs are kept in the order they were added or opened.

Closing the Tabs

Closing a Tab

If you don't want a file to be represented anymore by its tab, you can remove it. To close a file by its tab, you have many options:

Closing Other Tabs

If you have more than one tab that are currently displaying, you have the option of closing all tabs except one. To proceed, click the tab you want to keep. Right-click that tab and click Close Other Tabs.

Closing all Tabs

If you don't want to display any tab at all, you can close all types but keep the solution and project opened. To close all tabs:

If you have more than one tab that are currently displaying, you have the option of closing all tabs except one. To proceed, click the tab you want to keep. Right-click that tab and click Close Other Tabs.

Practical LearningPractical Learning: Ending the Lesson


Previous Copyright © 2001-2026, FunctionX Friday 19 December 2025, 18:55 Next