© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4mo ago•
59 replies
strikeouts27

✅ Can someone help me understand GetType()

Do I have to instantiate an object in order to use GetType()

using System;
using static System.Console;
using System.Globalization;
using System.Reflection.Metadata.Ecma335;

/*
Create an application class named LetterDemo that instantiates objects of two classes named Letter and CertifiedLetter and that demonstrates all their methods.

The classes are used by a company to keep track of letters they mail to clients. The Letter class includes auto-implemented properties for the Name of the recipient and the Date mailed (stored as strings).

Create a child class named CertifiedLetter that includes an auto-implemented property TrackingNumber (of type string) that holds a tracking number for the letter.

Next, include a ToString() method that overrides the Object class’s ToString() method and returns a string that contains the name of the class (using GetType()) and the respective class's data field values. Use default, empty constructor for both classes.
 
*/

class LetterDemo
{
    static void Main()
    {
        // Write your code here

        Letter letterObject = new Letter();
        Letter CertifiedLetter = new CertifiedLetter();

    }

    public class Letter()
    {
        private string Name;
        private string Date;

        public string Name { get; set; }
        public string Date { get; set; }

    }

    public class CertifiedLetter : Letter
    {
        private string TrackingNumber;
        public string TrackingNumber { get; set; }
    }
  
    
     public override string ToString()
     {
            string className = WriteLine(Letter.GetType());
            return className;
     }

}
using System;
using static System.Console;
using System.Globalization;
using System.Reflection.Metadata.Ecma335;

/*
Create an application class named LetterDemo that instantiates objects of two classes named Letter and CertifiedLetter and that demonstrates all their methods.

The classes are used by a company to keep track of letters they mail to clients. The Letter class includes auto-implemented properties for the Name of the recipient and the Date mailed (stored as strings).

Create a child class named CertifiedLetter that includes an auto-implemented property TrackingNumber (of type string) that holds a tracking number for the letter.

Next, include a ToString() method that overrides the Object class’s ToString() method and returns a string that contains the name of the class (using GetType()) and the respective class's data field values. Use default, empty constructor for both classes.
 
*/

class LetterDemo
{
    static void Main()
    {
        // Write your code here

        Letter letterObject = new Letter();
        Letter CertifiedLetter = new CertifiedLetter();

    }

    public class Letter()
    {
        private string Name;
        private string Date;

        public string Name { get; set; }
        public string Date { get; set; }

    }

    public class CertifiedLetter : Letter
    {
        private string TrackingNumber;
        public string TrackingNumber { get; set; }
    }
  
    
     public override string ToString()
     {
            string className = WriteLine(Letter.GetType());
            return className;
     }

}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

✅ Can someone help me understand this?
C#CC# / help
2w ago
can someone help me read and understand this
C#CC# / help
2y ago
❔ Can someone help me fully understand ref returns?
C#CC# / help
4y ago
Can someone please help me understand this StackOverflow answer?
C#CC# / help
4y ago