Hello All,
there was much talk about the fact that .NET doesn't support default
properties for objects, meaning that if in VB6 i could have Textbox1 =
"hello", in .NET i can do it only by refering explicitly to the property
Textbox1.Text = "hello".
why then some objects like DataRow still have default properties?
dr.Item("ID")
and
dr("ID")
both work fine and serve the same purpose
and of course, my quesion is how to create a default property for my own
classes? is it by including the Item property when i design my classes? or
is there some other tricks? :)
thank you,
Levon
avnrao - 07 May 2004 12:21 GMT
You can create default properties using
System.ComponentModel.DefaultPropertyAttribute.
Av.
> Hello All,
>
[quoted text clipped - 15 lines]
> thank you,
> Levon
William Ryan eMVP - 07 May 2004 14:26 GMT
If you have indexed properties (or indexers in C#) which basically means
more than 1 value in the property, then you can use Default properties.
Avnroe shows you how to do it with an attribute
http://www.knowdotnet.com/articles/properties2.html
> Hello All,
>
[quoted text clipped - 15 lines]
> thank you,
> Levon
Levon Levonian - 07 May 2004 14:23 GMT
Thank you guys,
so, the name of Item property is just a convention?
// levon
> If you have indexed properties (or indexers in C#) which basically means
> more than 1 value in the property, then you can use Default properties.
[quoted text clipped - 19 lines]
> > thank you,
> > Levon
William Ryan eMVP - 07 May 2004 21:20 GMT
Item is used by default but it could be any name you want. I'd recommend
using Item though in most cases to be consistent.
> Thank you guys,
>
[quoted text clipped - 26 lines]
> > > thank you,
> > > Levon