DotNetKick.com is an open-source project. Please report any bugs and let us know your great suggestions. Currently running svn revision 620 (rss)

Kick Spy!, Kick Zeitgeist and Kick Widgets

9
kicks
published 1 year, 5 months ago, submitted by crpietschmann crpietschmann 1 year, 5 months ago

pietschsoft.com — I've seen/used objects within the .NET Framework that have default properties (ie: SqlDataReader, System.Collections.Generic.List). Now how exactly do I give my own custom object type a default property?

Add a comment 9 comments | category: | Views: 23 | Get KickIt image code
tags: , , , | tag it

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:

Comments:
I don't get it- why's that peoperty a "default" property and not just a simple property? What's so special about it?
posted by marcoow 1 year, 5 months ago
The default property contains the 'this' keyword:

public Person this[int index]
{
get { return _people[index]; }
set { _people[index] = value; }
}

This allows you to access a person as follows:

club[0].Name = "John";

instead of

club.People[0].Name = "Joe";
posted by gavinjoyce gavinjoyce 1 year, 5 months ago
But that's an indexer... where did the name "Default property" come from?
posted by luciolucio 1 year, 5 months ago
BAAARRRR! You fail, default != indexer. Sorry, try again.
posted by yesthatmcgurk yesthatmcgurk 1 year, 5 months ago
Hey mr. Troll, very nice and intelligent comment, thank you so much. How about explaining the difference now?
posted by luciolucio 1 year, 5 months ago
Thought so...
posted by luciolucio 1 year, 5 months ago
well, maybe the author is coming from VB.NET because the indexer is specified by using the "Default" keyword. maybe?
posted by MarkoBarko 1 year, 5 months ago
Sorry for the confusion. The reason I called it a Default Property is because Microsoft has called it that in MSDN. Therefore, I have changed the title of my post to more accurately reflect what I've written about. Sorry for any confusion that may have been caused.

http://msdn2.microsoft.com/en-us/library/2b6akew6(VS.71).aspx
posted by crpietschmann crpietschmann 1 year, 5 months ago
That article says "The C# equivalent of a default Item property is an indexer." So it's the same after all. Thanks crpietschmann.
posted by luciolucio 1 year, 5 months ago



information Login or create an account to comment on this story
 

Sponsored Link: www.carlist.ie

Search:

Ads via The Lounge