Overloaded property accessor

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

int i;
public int pro1
        retrun i;
        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.

Question by:kingpreetham
LVL 37

Accepted Solution

gregoryyoung earned 100 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) ;
LVL 22

Assisted Solution

_TAD_ earned 100 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

Featured Post

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Through the video, you can check the migration process of Outlook PST file to PDF. Kernel for Outlook to PDF tool can convert Outlook emails with all attributes like Subject, To, From, Cc, Bcc and other folders such as Inbox, Outbox, Sent Items, Jun…

597 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