C#通过实例获取对象名称 [英] C# Get object name by instance

查看:35
本文介绍了C#通过实例获取对象名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

class A
{
 public object obj1 {get;set;}      
 public object obj2 {get;set;}      
 public object obj3 {get;set;}      
}

例如,我在某处有 obj2 的实例.如何在不使用类 A 或实例 A 的情况下获得它的名称(obj2")?

Somewhere i have instance of obj2 for example. How can i get its name ("obj2") without using class A or instance A?

推荐答案

你不能这样做.obj2 是类 A 的属性名称.因此,如果不使用类 A,您将无法知道其属性名称.

You can't do this. obj2 is the name of a property of the class A. So without using class A you cannot know its property names.

这篇关于C#通过实例获取对象名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆