Solved

Overloaded property accessor

Posted on 2004-08-05
4
230 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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

808 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