Sign Up

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

Have an account? Sign In

Have an account? Sign In Now

Sign In

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

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

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

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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

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

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

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

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

Mobile menu

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:57:56+00:00 2026-06-10T16:57:56+00:00

Let us say I have the following class.. Class Boy { public void hello()

  • 0

Let us say I have the following class..

Class Boy
{
    public void hello()
    {
        Console.WriteLine("Hello!");
    }
    static void Main(String[] args)
    {
            Boy a = new Boy();
            a.hello();
    }
}

I know that the variable ‘a’ is a reference variable of type ‘Boy’. The keyword ‘new’ created an object of ‘Boy’ assigning the address of it to the variable ‘a’.

Now, is it possible for me to get the name of my object. Does an object in C# have a name at all ?

  • 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-10T16:57:57+00:00Added an answer on June 10, 2026 at 4:57 pm

    I’m guessing you are referring to the name of the variable, “a”. Well, the thing is: that isn’t the name of the object – objects don’t have names. Further, an object can have zero one or multiple references to it, for example:

    var x = new SomeType(); // a class
    var y = x;
    

    Here both x and y refer to the same object. Equally:

    new SomeType();
    

    doesn’t have any references to it, but is still an object. Additionally, method variables (locals) don’t actually have names in IL – only in c# (for contrast, fields do have names). So new SomeType().WriteName(); would make no sense.

    So no: there is no sane way of getting the name of the variable from an object reference.

    If you want the object to have a name, add a Name property.

    There are some fun ways to get the name of a variable of field using expression trees, but I don’t think that is useful to what you are trying to do.

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

Sidebar

Related Questions

Let's say I have following POJO's using Hibernate. public class User { private String
Let's say I have the following classes : public class MyProductCode { private String
Let's say i have following class: template <typename T> class CModule{ public: virtual void
Let's say I have defined the following class: public abstract class Event { public
Let's say I have the following class hierarchy: class Base { protected: virtual void
let say i have following class: class Shape { public int widht; public List<Point>
Let's say I have the following class definition : List<SomeClass>... public class SomeClass {
Let's say I have the following class: class SQLMapper{ static find_user_by_id($id){ //sql logic here,
Let's say I have the following class structure (simplified from my real-world problem): Public
Background Let's say I have the following class: public class MyValue<T> { public T

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.