Click here to Skip to main content
15,904,934 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: I hate it when I am too clever for my own good... Pin
Brisingr Aerowing9-Feb-14 6:52
professionalBrisingr Aerowing9-Feb-14 6:52 
GeneralRe: I hate it when I am too clever for my own good... Pin
Mike Hankey9-Feb-14 7:23
mveMike Hankey9-Feb-14 7:23 
GeneralRe: I hate it when I am too clever for my own good... Pin
Andy Brummer9-Feb-14 14:57
sitebuilderAndy Brummer9-Feb-14 14:57 
JokeRe: I hate it when I am too clever for my own good... Pin
TnTinMn9-Feb-14 17:44
TnTinMn9-Feb-14 17:44 
GeneralRe: I hate it when I am too clever for my own good... Pin
BillWoodruff9-Feb-14 21:35
professionalBillWoodruff9-Feb-14 21:35 
GeneralRe: I hate it when I am too clever for my own good... Pin
OriginalGriff9-Feb-14 21:43
mveOriginalGriff9-Feb-14 21:43 
GeneralRe: I hate it when I am too clever for my own good... Pin
CBadger9-Feb-14 22:50
professionalCBadger9-Feb-14 22:50 
GeneralRe: I hate it when I am too clever for my own good... Pin
Fueled By Decaff10-Feb-14 0:31
Fueled By Decaff10-Feb-14 0:31 
You could do it by using a class that does the adding. You would need to specify the class to do the adding and the type it uses in the moving averages class.

Something like this:

C#
public interface IArithmetic<T>
{
    T Add(T augend, T addend);
}


C#
public class GenericAdd<T, U> where T : IArithmetic<U>, new()
{
    T adder = new T();

    public U AddGenericTypes(U augend, U addend)
    {
        return adder.Add(augend, addend);
    }
}



And for each type you want to use this with you will need one of these.

XML
public class AddInt : IArithmetic<int>
{
    public AddInt()
    {
    }

    #region IArithmetic<int> Members

    public int Add(int augend, int addend)
    {
        return augend + addend;
    }

    #endregion
}


These can then be used like this:

XML
GenericAdd<AddInt, int> intAdder = new GenericAdd<AddInt, int>();
int result = intAdder.AddGenericTypes(1, 2);




Seems like a lot of work to me unless you know you are going to need it.
GeneralRe: I hate it when I am too clever for my own good... Pin
irneb10-Feb-14 0:38
irneb10-Feb-14 0:38 
GeneralRe: I hate it when I am too clever for my own good... Pin
Gary Wheeler10-Feb-14 0:51
Gary Wheeler10-Feb-14 0:51 
GeneralRe: I hate it when I am too clever for my own good... Pin
OriginalGriff10-Feb-14 0:59
mveOriginalGriff10-Feb-14 0:59 
GeneralRe: I hate it when I am too clever for my own good... Pin
Gary Wheeler10-Feb-14 1:15
Gary Wheeler10-Feb-14 1:15 
GeneralRe: I hate it when I am too clever for my own good... Pin
OriginalGriff10-Feb-14 1:23
mveOriginalGriff10-Feb-14 1:23 
GeneralRe: I hate it when I am too clever for my own good... Pin
Gary Wheeler10-Feb-14 1:34
Gary Wheeler10-Feb-14 1:34 
GeneralRe: I hate it when I am too clever for my own good... Pin
Simon O'Riordan from UK10-Feb-14 5:09
Simon O'Riordan from UK10-Feb-14 5:09 
GeneralRe: I hate it when I am too clever for my own good... Pin
OriginalGriff10-Feb-14 5:32
mveOriginalGriff10-Feb-14 5:32 
GeneralRe: I hate it when I am too clever for my own good... Pin
James Curran10-Feb-14 1:40
James Curran10-Feb-14 1:40 
GeneralRe: I hate it when I am too clever for my own good... Pin
Richard Deeming10-Feb-14 3:48
mveRichard Deeming10-Feb-14 3:48 
GeneralRe: I hate it when I am too clever for my own good... Pin
Simon O'Riordan from UK10-Feb-14 5:07
Simon O'Riordan from UK10-Feb-14 5:07 
GeneralRe: I hate it when I am too clever for my own good... Pin
OriginalGriff10-Feb-14 5:30
mveOriginalGriff10-Feb-14 5:30 
GeneralRe: I hate it when I am too clever for my own good... Pin
RafagaX10-Feb-14 9:40
professionalRafagaX10-Feb-14 9:40 
GeneralRe: I hate it when I am too clever for my own good... Pin
Moreno Airoldi12-Feb-14 5:50
Moreno Airoldi12-Feb-14 5:50 
GeneralRick York share your dissatisfaction Pin
Sanmayce9-Feb-14 4:45
Sanmayce9-Feb-14 4:45 
GeneralRe: Rick York share your dissatisfaction Pin
OriginalGriff9-Feb-14 5:02
mveOriginalGriff9-Feb-14 5:02 
GeneralRe: Rick York share your dissatisfaction Pin
Sanmayce9-Feb-14 5:18
Sanmayce9-Feb-14 5:18 

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.