[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Argument lists for property get/set

Posted on 2003-02-24
3
Medium Priority
?
671 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
  • 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

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

590 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