Sign Up

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

Have an account? Sign In

Have an account? Sign In Now

Sign In

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

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

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

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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

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

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

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

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

Mobile menu

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:52:35+00:00 2026-06-16T09:52:35+00:00

Possible Duplicate: Get type name without full namespace in C# Does anybody know how

  • 0

Possible Duplicate:
Get type name without full namespace in C#

Does anybody know how we can get the name of a class in a simple way like what Java can do via class.getName() ?

NB: Yes, there are some messy workaround like CreateInstance of the class type and then get the name of object but I want a simple way.

Edit 1:

Actually, I need the class name in a method say X. Meanwhile, I don’t want to loose type-safety and I’m not gonna allow other developers to pass a string to the method. Something like this:

void X( ??? class) // --> don't know how
{
     var className = get the name of class // --> which I don't know how
     Console.WriteLine(className);
}

X(tblEmployee); //--> usage of X, where tblEmployee is a POCO class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:52:36+00:00Added an answer on June 16, 2026 at 9:52 am

    You mean, like this?

    typeof(YourClass).Name
    

    To clarify, in .NET framework there’s a class named Type. This class has a property named Name that retrieves the name of the class.

    So, to retrieve the Type of a class in compile time you can use typeof.

    var typeName = typeof(YourClass).Name
    

    If you doesn’t know the type at runtime, you can retrieve it with the GetType() method. This is common for all .NET objects.

    Animal a = new Dog();
    var typeName = a.GetType().Name;
    

    Answer for Edit 1

    You need to pass a Type parameter

    void X(Type classType) 
    {
         var className = classType.Name;
         Console.WriteLine(className);
    }
    

    And a call to X should be like this

    X(typeof(YourClass));
    

    or

    X(YourInstance.GetType());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Get variable name. javascript “reflection” Is there a way to know the
Possible Duplicate: How can I get the primitive name of a type in C#?
Possible Duplicate: How can I get the name of function inside a JavaScript function?
Possible Duplicates: Get method name and type using lambda expression Can I use Expression<Func<T,
Possible Duplicate: PHP detecting request type (GET, POST, PUT or DELETE) This should be
Possible Duplicate: Default value of a type In C#, to get the default value
Possible Duplicate: Get file name from URI string in C# How to extract file
Possible Duplicate: Get full path of a file with FileUpload Control I want to
Possible Duplicate: Why do I get error: … must be a reference type in
Possible Duplicate: g++ “is not a type” error The following does not compile: 1

Explore

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

Footer

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

Insert/edit link

Enter the destination URL

Or link to existing content

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