Default Property

  • Thread starter Thread starter Levon Levonian
  • Start date Start date
L

Levon Levonian

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
 
You can create default properties using
System.ComponentModel.DefaultPropertyAttribute.

Av.
 
Thank you guys,

so, the name of Item property is just a convention?

// levon
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top