Results 1 to 4 of 4

Thread: Overload SET accessor in C#

  1. #1
    Join Date
    Nov 2008
    Posts
    1,221

    Overload SET accessor in C#

    I want to overload my SET accessor.

    Basically, if a string is passed as a parameter, I do a certain action (here, I created a new instance of the class Mailbox then I assign) or if it is an instance of Mailbox I assign directly .

    Of overloading method what.

    The problem is that the code No. 1 launches me compilation error (Error 2 The type 'CoreNet.Common.WebElement.MailStyle' already contains a definition for 'From') and the No. 2 code compiles well which is normal.

    Code:
    public string From 
    {
    set 
    {
    base.From = new MailAddress(value);
    }
    }
    public MailAddress From
    {
    set { base.From = value;); }
    }
    Which ultimately would like this:

    Code:
    public void SetFrom (string Mail) 
    {
    base.From = new MailAddress(Mail);
    }
    public void SetFrom(MailAddress Mail) 
    {
    base.From = Mail;); 
    }
    C# to implement this syntax to replace the methods SetXXXX Java, Java allows overloading of property of a SET, I do not understand why this is not possible in C#

    How?

  2. #2
    Join Date
    Feb 2008
    Posts
    194

    Re: Overload SET accessor in C#

    I do not understand why this is not possible in C#
    It is not possible because 1. stupid and 2. not the use case. A property is a property, is equivalent to a member variable with potentially the logic behind. If you want to override the methods you use methods.

  3. #3
    Join Date
    May 2008
    Posts
    945

    Re: Overload SET accessor in C#

    Why overload string From if it is the same as the parent class

  4. #4
    Join Date
    May 2008
    Posts
    685

    Re: Overload SET accessor in C#

    It actually has no interest of wanting to overburden the type of property. Therefore prohibited. JAVA manages it so differently, which is an advantage in this case, but is a big disadvantage in terms of readability of code.

Similar Threads

  1. System overload in Skype
    By pasture in forum Technology & Internet
    Replies: 2
    Last Post: 16-10-2011, 06:50 AM
  2. System overload due to malware
    By Omanand in forum Networking & Security
    Replies: 5
    Last Post: 16-07-2011, 08:19 PM
  3. how to overload a function in c++
    By Calandar in forum Software Development
    Replies: 4
    Last Post: 08-01-2011, 10:32 AM
  4. Overload resolution failed
    By Preetish in forum Software Development
    Replies: 2
    Last Post: 25-02-2009, 03:28 PM
  5. Suffering from 100% cpu overload
    By Renderman21 in forum Windows Software
    Replies: 4
    Last Post: 13-08-2008, 02:34 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,285,853.92980 seconds with 17 queries