.tag在C#中的作用是什么,请详细说明 [英] what do .tag work in c# please details

查看:116
本文介绍了.tag在C#中的作用是什么,请详细说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.tag在c#中如何工作,请详细说明

what do .tag work in c# please details

推荐答案


Tag属性在从Control派生的所有对象上都可用-窗体,按钮,文本框等,并且免费提供给您放置喜欢的东西!由于它包含从object派生的任何事物,因此可以包含任何事物的实例!

我使用它的目的之一是为项目列表保留相关的类实例.例如,如果您具有ListView,则可以将项目设置为用户想要查看的内容,将Tag设置为内部信息-类实例.

然后,您要做的就是用户选择一个项目,获取Tag属性,将其强制转换为您的类的实例,然后直接使用它.
The Tag property is available on all objects derived from Control - forms, buttons, textboxes, etc. and is freely available for you to put whatever you like in! Since it holds any thing derived from object it can hold an instance of anything!

One of the things I use it for is to hold the relevant class instance for a list of items. If you have a ListView for example, you can set the item to something the user wants to see, and the Tag to the internal information - the class instance.

All you have to do then, is when the user selects an item, get the Tag property, cast it to an instance of your class, and use it directly.


这篇关于.tag在C#中的作用是什么,请详细说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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