Click here to Skip to main content
15,912,069 members
Home / Discussions / C#
   

C#

 
Questionoverload operator + Pin
al3xutzu0015-Apr-09 2:16
al3xutzu0015-Apr-09 2:16 
AnswerRe: overload operator + Pin
Dino Mulahusic15-Apr-09 2:25
professionalDino Mulahusic15-Apr-09 2:25 
AnswerRe: overload operator + Pin
0x3c015-Apr-09 2:28
0x3c015-Apr-09 2:28 
GeneralRe: overload operator + Pin
al3xutzu0015-Apr-09 2:41
al3xutzu0015-Apr-09 2:41 
GeneralRe: overload operator + Pin
0x3c015-Apr-09 3:05
0x3c015-Apr-09 3:05 
GeneralRe: overload operator + Pin
Luc 64801115-Apr-09 3:20
Luc 64801115-Apr-09 3:20 
GeneralRe: overload operator + Pin
OriginalGriff15-Apr-09 4:08
mveOriginalGriff15-Apr-09 4:08 
GeneralRe: overload operator + Pin
DaveyM6915-Apr-09 4:39
professionalDaveyM6915-Apr-09 4:39 
I agree to a point. There are situations where it could be acceptable (the OP's may be one).

To continue your adding apples and oranges analogy, imagine a class FruitBasket that has a List of Apples. Adding a new Apple to the basket via an overloaded + binary operator could make sense. I prefer exposing the list of Apples as a property so it's Add method can be called directly or creating an AddApple method, but it's not 'bad' IMO.
public class FruitBasket
{
    private List<Apple> _Apples;
    public FruitBasket()
    {
        _Apples = new List<Apple>();
    }
    public static FruitBasket operator +(FruitBasket basket, Apple apple)
    {
        basket._Apples.Add(apple);
        return basket;
    }
}
public class Apple
{
    public Apple(string name)
    {
        Name = name;
    }
    public string Name
    {
        get;
        set;
    }
}


Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)

GeneralRe: overload operator + Pin
OriginalGriff15-Apr-09 5:10
mveOriginalGriff15-Apr-09 5:10 
Questionretrieve object multiple return with different types question? Pin
michaellu8815-Apr-09 2:14
michaellu8815-Apr-09 2:14 
AnswerRe: retrieve object multiple return with different types question? Pin
0x3c015-Apr-09 2:24
0x3c015-Apr-09 2:24 
GeneralRe: retrieve object multiple return with different types question? Pin
michaellu8815-Apr-09 15:14
michaellu8815-Apr-09 15:14 
Questionjoin Pin
sheemap15-Apr-09 1:40
sheemap15-Apr-09 1:40 
GeneralRe: join Pin
Pete O'Hanlon15-Apr-09 1:43
mvePete O'Hanlon15-Apr-09 1:43 
GeneralRe: join Pin
sheemap15-Apr-09 1:47
sheemap15-Apr-09 1:47 
GeneralRe: join Pin
Luc 64801115-Apr-09 2:02
Luc 64801115-Apr-09 2:02 
GeneralRe: join Pin
EliottA15-Apr-09 3:13
EliottA15-Apr-09 3:13 
GeneralRe: join Pin
0x3c015-Apr-09 4:30
0x3c015-Apr-09 4:30 
RantRe: join Pin
musefan15-Apr-09 2:34
musefan15-Apr-09 2:34 
AnswerRe: join Pin
tom57200715-Apr-09 2:53
tom57200715-Apr-09 2:53 
Questionproblem in setting backround image to a form created using OpenGL in c# Pin
raesa15-Apr-09 1:34
raesa15-Apr-09 1:34 
Questionhow to write string in PDF Pin
wasimsharp15-Apr-09 1:10
wasimsharp15-Apr-09 1:10 
AnswerRe: how to write string in PDF Pin
stancrm15-Apr-09 1:18
stancrm15-Apr-09 1:18 
GeneralRe: how to write string in PDF Pin
wasimsharp15-Apr-09 18:23
wasimsharp15-Apr-09 18:23 
AnswerRe: how to write string in PDF Pin
tom57200715-Apr-09 2:56
tom57200715-Apr-09 2:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.