Solved

Overloaded property accessor

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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