?
Solved

Argument lists for property get/set

Posted on 2003-02-24
3
Medium Priority
?
668 Views
Last Modified: 2012-08-13
How do you have parameterised property gets and sets in c#? in vb6 and vb.net you can have an argument list in the declaration, but in c# it seems that the argument list (or lack of it) is what distinguishes a method from a property.
e.g

public int Answer
{
get { return x;}
}

is fine but :

public int Answer(int index)
{
 get {return arrayofresults[index];}
}

doesn't work.

Thanks,

Ian.


0
Comment
Question by:ReAdm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Accepted Solution

by:
merith earned 150 total points
ID: 8009767
You are right, this is a major difference between the two, however if you make the class indexable you might be able to get what you are after.
0
 

Author Comment

by:ReAdm
ID: 8010153
Yes, but you can only have one indexer per class, and with some collection classes it's nice to expose several properties by index, without exposing any arrays or collections. But I Guess I just can't do it, I'll have to write seperate 'getproperty' and 'setproperty' methods. Grrr. Seems really odd that vb.net allows such things and c# doesn't.
0
 

Author Comment

by:ReAdm
ID: 8011522
Okay, having done some thinking I tried creating a vb.net project with a class that has a parameterised get/set to see what c# would make of it when referencing it. c# turns it into a get_Property and set_Property method! I guess its frigged in vb.net to keep old vb'ers happy, and c++ programmers should know better than to mix collections and content. Hey ho.
I.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question