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 symbol, something to click, something to select, etc. An object is created from a type. The .NET Framework provides many options and Microsoft Visual Studio offers many tools.

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. Start Microsoft Visual Studio
  2. In the Visual Studio 2026 dialog box, click Create A New Project
  3. In the Create A New Project dialog box, below Recent Project Templates, click Blank Solution
  4. Click Next
  5. Change the Solution Name to Geometry
  6. Click Create
  7. To add a project, in the Solution Explorer, right-click GeometricShapes -> Add -> New Project...
  8. In the Add New Project dialog box, in the languages combo box, select All Languages
  9. In the list of projects templates, make sure Console App is selected.
    Click Next
  10. Change the Project Name to Polygonals
  11. Click Create
  12. In the Configure Your New Project dialog box, make sure the Framework combo box is displaying the highest version.
    Click Create
  13. In the Solution Explorer, right-click Program.cs -> Rename
  14. Type Evaluations (to get Evaluations.cs) and press Enter
  15. To create an interface, in the Solution Explorer, right-click Polygonals -> Add -> Class...
  16. In the middle list of the Add New Item dialog box, click Interface
  17. Change the file Name to IDescription
  18. Click Add
  19. Change the document as follows:
    namespace Polygonals
    {
        internal interface IDescription
        {
            public abstract void Describe();
        }
    }
  20. To create another interface, in the Solution Explorer, right-click Polygonals -> Add -> Class...
  21. In the middle list of the Add New Item dialog box, click Interface
  22. Change the file Name to IPolygon
  23. Click Add
  24. 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

The C# language provides various objects to let you create obfects. Options includde structures, records, and classes. 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();
    Triangle tri  = new Triangle();
    
    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.

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

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 variable are declared:
    Square sqr    = new Square();
    Rhombus rho   = new Rhombus();
    IPolygon pent = new Pentagon();
    Triangle tri  = new Triangle();
    
    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. In the DOS window, press U to close the window and return to your programming environment
  10. To create another class, on the main menu, click Project and click Add Class...
  11. Change the file Name to Heptagon
  12. Click Add
  13. In the DOS window, press U to close the window and return to your programming environment
  14. To create another class, on the main menu, click Project and click Add Class...
  15. Change the file Name to Octagon
  16. Click Add
  17. In the DOS window, press U to close the window and return to your programming environment
  18. To create another class, on the main menu, click Project and click Add Class...
  19. Change the file Name to Nonagon
  20. Click Add
  21. To create another class, on the main menu, click Project and click Add Class...
  22. Change the file Name to Decagon
  23. Click Add
  24. To add a project, in the Solution Explorer, right-click Geometry -> Add -> New Project...
  25. Click the arrow of the languages combo box of the Add New Project dialog box and select Visual Basic
  26. Below the languages combo box, make sure Console App is highlighted (if not, click Console App).
    Click Next
  27. Change the Project Name to Volumetrics
  28. Click Next
  29. In the Additional Information wizard page, click Create
  30. To create another interface, in the Solution Explorer, right-click Volumetrics -> Add -> Class...
  31. Change the file Name to Square
  32. Click Add
  33. 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
  34. To create an interface, in the Solution Explorer, right-click Volumetrics -> Add -> Class...
  35. Change the file Name to Cube
  36. Click Add
  37. 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
  38. To create an interface, in the Solution Explorer, right-click Volumetrics -> Add -> Class...
  39. Change the file Name to Rectangle
  40. Click Add
  41. 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
  42. To create an interface, in the Solution Explorer, right-click Volumetrics -> Add -> Class...
  43. Change the file Name to Box
  44. Click Add
  45. 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
  46. To create a class, in the Solution Explorer, right-click Volumetrics -> Add -> Class...
  47. Change the file Name to TriangularPrism
  48. Click Add
  49. To create an interface, in the Solution Explorer, right-click Volumetrics -> Add -> Class...
  50. Change the file Name to PentagonalPrism
  51. Click Add
  52. To create an interface, in the Solution Explorer, right-click Volumetrics -> Add -> Class...
  53. Change the file Name to HexagonalPrism
  54. Click Add
  55. To create an interface, in the Solution Explorer, right-click Volumetrics -> Add -> Class...
  56. In the middle list of the Add New Item dialog box, click Interface
  57. Change the file Name to ICircular
  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 Circle
  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 Sphere
  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 Cone
  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 Cylinder
  70. Click Add
  71. To create a class, in the Colution Explorer, right-click Volumetrics and click Add Class...
  72. Change the file Name to Tank
  73. Click Add
  74. In the Solution Explorer, below Volumetrics, right-click Program.vb and click Rename
  75. Replace Program with Preparations (to get Preparations.vb) and press Enter twice to save the file and access it
  76. 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
  77. 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 . . .
  78. Press I to close the DOS window and return to your programming environment
  79. To add a project, in the Solution Explorer, right-click Geometry -> Add -> New Project...
  80. Click the arrow of the languages combo box of the Add New Project dialog box and select F#
  81. Below the languages combo box, make sure Console App is highlighted (if not, click Console App).
    Click Next
  82. Change the Project Name to Polyhedrons
  83. Click Next
  84. In the Additional Information wizard page, click Create
  85. In the Solution Explorer, below Polyhedrons, right-click Program.fs and click Rename
  86. Type Structurals (to get Structurals.fs) and press Enter
  87. To start a class, in the Solution Explorer, right-click Polyhedrons -> Add -> New Item...
  88. 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
  89. Click Add
  90. To start a class, in the Solution Explorer, right-click Polyhedrons -> Add -> New Item...
  91. Change the file Name to Hexahedron
  92. Click Add
  93. To start a class, in the Solution Explorer, right-click Polyhedrons -> Add -> New Item...
  94. Change the file Name to Pentahedron
  95. Click Add
  96. To start a class, in the Solution Explorer, right-click Polyhedrons -> Add -> New Item...
  97. Change the file Name to Dodecahedron
  98. Click Add
  99. To start a class, in the Solution Explorer, right-click Polyhedrons -> Add -> New Item...
  100. Change the file Name to Tetrahedron
  101. Click Add

Opening a File

Introduction

As you should be aware now, a project is made of many code files, including C# 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

If you are working with Microsoft Visual Studio, you can open various types of files. The primary types of files you can easily open are text-based files, including those from programming languages: C#, C++, Visual Basic, Python, HTML, CSS, JavaScript, SQL, etc. You can also open graphics file. To start, on the main menu of Microsoft Visual Studio, click File -> Open -> File... Locate the folder or directory where the file exists. Click the desired file and click Open. If the file is easily recognizable, Microsoft Visual Studio would open it and display its contents. If you open a complex file, such as a graphics file, Microsoft Visual Studio would display a warning message box requesting your permission:

Microsoft Visual Studio - Opening a File - A Warning

If you click Yes on the message box, Microsoft Visual Studio would open and display the file. If you click No, nothing else would happen.

If you select a file that Microsoft Visual Studio can't open or doesn't want to open, it would display an error message box:

Microsoft Visual Studio - Opening a File - An Error Message

Opening a Recent File

Microsoft Visual Studio keeps a list of files that were previously opened. To see that list, on the main menu of Microsoft Visual Studio, click File and position the mouse on Recent Files. By default, Microsoft Visual Studio keeps a list of the ten files that were recently opened. To manage this number, on the main menu of Microsoft Visual Studio, click Tools and click Options... If you want, change the value of the Items To Show In Recent Used File List:

Locals

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.

Opening a File from Window

The main menu of Microsoft Visual Studio is equipped with a menu category titled Window. Besides some items that are used to manage some window options, the Window menu item holds a list (or collection) of the files that are currently opened in Microsoft Visual Studio. Every time you open a file, the name (and path) of that file is added to the Window list. To see the list of files, click Window. Each entry displays with an ordered number and the path to the file.

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.

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