C#后期绑定问题 [英] C# Late Binding problem

查看:69
本文介绍了C#后期绑定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在C#中定义了一个对象

i Have Defined a object in C#

object obj=null;



现在,我会使用
在我的软件中对其进行初始化



now iam instializing it in my software with

obj= someobject;


通过后期绑定

现在我想访问它的属性,

我如何在c#中实现它?


through late binding

now i want to access its proprities,

How can i achive it in c# ?

推荐答案

如果您确定该对象实现了特定的接口,则可以将对象放在该接口上并访问其成员. .通常这会更快.

另一方面,如果不确定任何已实现的接口,则可以使用Reflection执行此操作. 请参阅此处 [
If you know for sure that the object implements a specific interface, you can case your object to that interface and access its members. This is usually faster.

On the other hand, if you are not sure of any implemented interfaces, the you can use Reflection to do this. See here[^]. Reflection is very slow and not recommended unless absolutely required.


这篇关于C#后期绑定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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