multiple parameters in properties

hi,

how do I create property with multliple parameters, this one supports only one parameter.

public int X
{
     get
     {
          return x;
     }
     set
     {
          x = value;
     }
}
LVL 13
davidlars99Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ravi SinghSenior Software EngineerCommented:
Hi, you can't create a property that accepts multiple parameters, they are usually used to allow read/write or read only access to a single field in your class. I think you'll have to use setter/getter methods in your case.

public void SetMethod(int a, int b, ...)
{
   this.a = a;
   this.b = b;
   ...
}

public int GetA()
{
   return this.a;
}
...
PoeticAudioCommented:
david,

Are you talking about indexers?

http://www.csharphelp.com/archives/archive140.html
PoeticAudioCommented:
I am confused to the way you're using the word parameter. The property you defined doesn't have any parameters, methods have parameters as Zephyr pointed out.
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Bob LearnedCommented:
VB.NET supports properties with multiple arguments:

  Public ReadOnly Property GetImage(ByVal folder As String, ByVal index As Integer) As Image
    Get
      Return Image.FromFile(IO.Directory.GetFiles(folder)(index))
    End Get
  End Property

But, I don't believe the C# supports that kind of syntax.

Bob
KelmenCommented:
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/msg/5ecdc90355e21939

in C# , using indexer

 public string this [int param1, int param2]
 {
     get
        {
                return myprop;
        }
     set
        {
                myprop = value;
        }
 }
Bob LearnedCommented:
Indexers are not exactly the same thing, since you can't name the property.

Bob
KelmenCommented:
then try this:

class B {
  public Image this[string, int] {
    get {...}
    set {...}
} }

class A {
  private B _b;
  public B GetImage{
    get { return _b; }
    set {...}
} }

using-
A objA;
objA.GetImage[string, int] = ...
... = objA.GetImage[string, int]
davidlars99Author Commented:
-->  Indexers are not exactly the same thing, since you can't name the property.

what is the distinctions?
Bob LearnedCommented:
Definition of indexers:

http://msdn2.microsoft.com/en-us/library/6x16t2tx.aspx

<Quote>
Indexers permit instances of a class or struct to be indexed in the same way as arrays. Indexers are similar to properties except that their accessors take parameters.
</Quote>

If you have an indexer, then you can short-cut the syntax.   Here is an example of syntax for a DataRow:

DataRow row = table.Rows[0];
row.Item[0] = "Bob";

    short-cuts to

DataRow row = table.Rows[0];
row[0] = "Bob";

In this case, Item is an indexer property.

Bob

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.