Solved

Overloaded property accessor

Posted on 2004-08-05
4
232 Views
Last Modified: 2010-04-15
I have a question on overloading property accessor.
I have a property defined below:

int i;
public int pro1
{
    get
    {
        retrun i;
    }
    set
    {
        i = value;
    }
}

here value is an implicit parameter sent to the property of type integer.
Is there any way i can have an overloaded accessor which takes a string, then does and Int32.Parse() and
setsthe value of i.

Thanks,
Preetham.
0
Comment
Question by:kingpreetham
[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
4 Comments
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 25 total points
ID: 11730045
no ... instead I would just use methods (which is all the property really creates)

public int get_pro1 {
       return i;
}

public void set_pro1(int value) {
       i = value ;
}

public void set_pro1(string value) {
       i = int.Parse(value) ;
}
0
 
LVL 22

Assisted Solution

by:_TAD_
_TAD_ earned 25 total points
ID: 11730998


your other option is to box everything.  You'll take a bit of a performance hit (not much, but its there), but it will make your code smaller.

int i;
public object pro1
{
   get{}  //box and unbox here
   set{}  //box and unbox here
}
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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