Click here to Skip to main content
15,886,578 members
Home / Discussions / C#
   

C#

 
AnswerRe: Toggle button in a datatemplate with command binding using MVVM design approach Pin
Kenneth Haugland7-Jan-18 17:32
mvaKenneth Haugland7-Jan-18 17:32 
GeneralRe: Toggle button in a datatemplate with command binding using MVVM design approach Pin
Hervend8-Jan-18 0:04
Hervend8-Jan-18 0:04 
GeneralRe: Toggle button in a datatemplate with command binding using MVVM design approach Pin
Kenneth Haugland8-Jan-18 1:08
mvaKenneth Haugland8-Jan-18 1:08 
Questionhow to get alert while working in c# windows application Pin
Member 30804705-Jan-18 23:07
Member 30804705-Jan-18 23:07 
AnswerRe: how to get alert while working in c# windows application Pin
OriginalGriff6-Jan-18 0:55
mveOriginalGriff6-Jan-18 0:55 
AnswerRe: how to get alert while working in c# windows application Pin
BillWoodruff6-Jan-18 2:53
professionalBillWoodruff6-Jan-18 2:53 
AnswerRe: how to get alert while working in c# windows application Pin
Gerry Schmitz6-Jan-18 7:28
mveGerry Schmitz6-Jan-18 7:28 
Questionextending a special case of a generic type Pin
Alexander Kindel5-Jan-18 22:10
Alexander Kindel5-Jan-18 22:10 
I'm working on a program that needs to model polynomials. The program has a Number class, and an Integer class that derives from it. There is some polynomial behavior that applies to polynomials with any Number coefficients, and some, like getPsuedoRemainder(), that applies only to Integer coefficient polynomials. This seemed to me like a natural application of class inheritance. I tried a structure like this,

C#
class Polynomial<T> where T : Number
{
    List<T> Coefficients { get; }
    public Polynomial(List<T> coefficients)
    {
        Coefficients = coefficients;
    }
}
class IntegerPolynomial : Polynomial<Integer>
{
    public IntegerPolynomial(List<Integer> coefficients) : base(coefficients)
    { }
}


with the operations that apply to both classes, like addition and multiplication, defined in Polynomial<t>* and the Integer-specific ones defined in IntegerPolynomial. However, I ran into trouble choosing appropriate return types for the operations defined in Polynomial<t>. For example, the sum of two Polynomial<number> objects needs to be either another Polynomial<number> object or something that is castable to one, and likewise for IntegerPolynomial objects. This is the case because I need to be able to, for example, add two IntegerPolynomials and call getPsuedoRemainder() on the result. In order for the Polynomial<number> case to work out correctly, as far as I can tell that leaves me the choice between the following two signatures:

C#
public static Polynomial<T> operator +(Polynomial<T> a, Polynomial<T> b)
public static Polynomial<Number> operator +(Polynomial<T> a, Polynomial<T> b)


The latter obviously doesn't also make sense for the IntegerPolynomial case. The former almost does, in that it would return Polynomial<integer> objects, but I've found that it isn't legal to cast from Polynomial<integer> to IntegerPolynomial.

Is there a way to tweak this structure so that the types work out? Or is there a much different structure that would be more appropriate?

*The preview shows every type I have in angled brackets inline in paragraphs as lower-case even though I typed them all as upper-case, as in the code examples. If you see the discrepancy, note that it isn't meaningful.

modified 6-Jan-18 4:19am.

GeneralRe: extending a special case of a generic type Pin
harold aptroot5-Jan-18 22:38
harold aptroot5-Jan-18 22:38 
GeneralRe: extending a special case of a generic type Pin
Alexander Kindel5-Jan-18 23:09
Alexander Kindel5-Jan-18 23:09 
GeneralRe: extending a special case of a generic type Pin
harold aptroot5-Jan-18 23:34
harold aptroot5-Jan-18 23:34 
GeneralRe: extending a special case of a generic type Pin
Alexander Kindel5-Jan-18 23:37
Alexander Kindel5-Jan-18 23:37 
GeneralRe: extending a special case of a generic type Pin
Alexander Kindel6-Jan-18 2:39
Alexander Kindel6-Jan-18 2:39 
AnswerRe: extending a special case of a generic type Pin
jschell6-Jan-18 6:06
jschell6-Jan-18 6:06 
GeneralRe: extending a special case of a generic type Pin
Alexander Kindel6-Jan-18 8:28
Alexander Kindel6-Jan-18 8:28 
GeneralRe: extending a special case of a generic type Pin
jschell8-Jan-18 14:59
jschell8-Jan-18 14:59 
QuestionProblem with click event of a button on C # Pin
BEN SBAI5-Jan-18 13:41
BEN SBAI5-Jan-18 13:41 
AnswerRe: Problem with click event of a button on C # Pin
Jim Meadors5-Jan-18 16:06
Jim Meadors5-Jan-18 16:06 
AnswerRe: Problem with click event of a button on C # Pin
OriginalGriff5-Jan-18 20:04
mveOriginalGriff5-Jan-18 20:04 
AnswerRe: Problem with click event of a button on C # Pin
BillWoodruff5-Jan-18 21:33
professionalBillWoodruff5-Jan-18 21:33 
GeneralRe: Problem with click event of a button on C # Pin
OriginalGriff5-Jan-18 21:46
mveOriginalGriff5-Jan-18 21:46 
GeneralRe: Problem with click event of a button on C # Pin
BillWoodruff6-Jan-18 2:46
professionalBillWoodruff6-Jan-18 2:46 
QuestionDisabling events of objects stored in array Pin
Pogoodill5-Jan-18 2:32
Pogoodill5-Jan-18 2:32 
AnswerRe: Disabling events of objects stored in array Pin
OriginalGriff5-Jan-18 3:14
mveOriginalGriff5-Jan-18 3:14 
GeneralRe: Disabling events of objects stored in array Pin
Pogoodill5-Jan-18 3:55
Pogoodill5-Jan-18 3:55 

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.