在C#中转换对象 [英] Converting Object in C#

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

问题描述

我想将System.Windows.Forms.TextBox类的对象转换为System.Windows.Controls.TextBox类的对象?

I want to convert System.Windows.Forms.TextBox class's object to System.Windows.Controls.TextBox class's object ?

推荐答案

你不能 - 没有任何共同之处,尤其不是它们的类层次结构。

Forms.TextBox是一个WinForms组件,而Controls.TextBox是一个WPF组件:你不能只将它们视为可互换的!
You can't - the have nothing in common, especially not their class hierarchy.
Forms.TextBox is a WinForms component, and Controls.TextBox is a WPF component: you can't just treat them as interchangeable!


你的问题的回答是为什么会这样做

尽管如此,这两个课程来自不同的框架,这意味着你不能那样做。



-KR
Answer to your question is WHY WOULD ANYONE DO THAT ?
Still, both the classes are from different framework, so that means you can't do that.

-KR


没有。你不能。

你能做的最好的就是创建这些控件并将一个控件的一些属性分配给另一个。
No. You can't.
The best you can do is create both these controls and assign some properties of one control to another.


这篇关于在C#中转换对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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