Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
how to make parameterized properties in c#
Posted
Comments
BobJanova 16-Mar-12 7:49am    
Do you mean parameterised queries (for database lookup)? If not, I don't really know what this question is trying to ask.

here is an example found in MSDN:

C#
public WebSite this[int index]
{
   get
      {    
          if (index > sites.Count)    
            return (WebSite)null;    

          return (WebSite) sites.GetByIndex(index);
      }
   set
      {    
         if ( index < 10 )    
           sites[index] = value;
      }
}


The only parametrized properties you can make are indexers if I am not mistaken.
 
Share this answer
 
The only type of parameterized property you can create in C# is an indexer property:

C#
public class MyConnectionStrings
{
    private string GetConnectionString(string connectionName) { ... }

    public string this[string connectionName]
    {
        get { return GetConnectionString(connectionName); }
    }
}

for more refer:http://msdn.microsoft.com/en-us/library/6x16t2tx.aspx[^]


Otherwise, just create a method instead - that seems to be closer to what you are looking for, a shown in :
http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/1c813b3e-7049-465c-8439-61e37e8a07ba/[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900