将字符串值类型转换为 System.Windows.Forms.Label 类
注意
我支持以下观点:以下问题是不可能完成的。 请不要误解我。 这不是我。请仔细阅读问题。
我参与了关于将 string
值类型转换为 System.Windows.Forms.Label
类的讨论。其他人都支持这是可能的,但对我来说,当前版本的 C# 是不可能的。
我错过了什么吗?这家伙正在尝试以下代码;
注2
下面的代码不是我写的!
lbl=((Label)("label"+"1"));
我不知道我只是无知,但这对我来说太不可能了,甚至乔恩·斯基特也能做到。
这是怎么回事?
NOTE
I am supporting the idea that the below issue is way impossible to do.
Pls, do not misunderstand me.
It is not me. Please read the question carefully.
I have involved a discussion about casting string
value type to System.Windows.Forms.Label
Class. Other guys have supported that it is possible but for me, it is impossible with current release of C#.
Am I missing something? The guy is trying the following code;
NOTE-2
The below code is not written by me !
lbl=((Label)("label"+"1"));
I don't know that I am being just ignorant but it is so impossible for me that it can be even done by Jon Skeet.
what is the deal here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
然而,代码可以工作的唯一方法是创建一个强制转换运算符他们必须在类型声明中定义它,并且
string
和Label
都没有这样的转换运算符。他们想要在表单上获得名为 label1 的标签吗?
如果是这样,他们可以使用
Page
的FindControl
或放置标签的控件。The only way that code could work is by creating a casting operator, however they have to define that within the type declaration, and neither
string
norLabel
have such a casting operator.Do they want to get the label on their form called label1?
If so, they can use the
FindControl
ofPage
, or the control that the label is placed on.无法将字符串转换为标签。
你可以尝试这样的事情,但这不是演员阵容。
It is not possible to cast a String to Label.
You could try something like this, but it is not a cast.