开发者

What use does the *tag* attribute have in C#

I've been working with C# for over a year now, and I was wondering what other functionality the tag attribute has of a control, till now each .net control I've used (buttons, labels, textboxes, gridview, etc.) have a tag attribute that you can define.

I only know you can put something in it like a string of text.

The visual studio description says:

User-defined data associat开发者_JS百科ed with the control

Does the tag do anything else than that? Describe it's content? And where do you use if for? Has it been of use to any of you?


No, it does nothing in itself. It's up to you to use it however you want to. For example, you could use it to do a sort of simplified databinding, such that you put the user-visible text in a checkbox, and the value to store in the database (e.g. an enum value) in the tag. Then you retrieve it from the tag later on.

IME it's usually useful for "quick and dirty" scenarios where there are better ways of working, but they take a bit longer to code up - which is fine for throwaway code, but not ideal for a complex production system. That may not always be the case, of course.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜