Solved

Overloaded property accessor

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now