开发者

Casting a string value type to System.Windows.Forms.Label Class

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开发者_JAVA技巧 done by Jon Skeet.

what is the deal here?


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 nor Label have such a casting operator.


Do they want to get the label on their form called label1?

If so, they can use the FindControl of Page, 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.

lbl = new Label() { Text = "Label" + "1" };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜