Click here to Skip to main content
15,887,350 members
Home / Discussions / C#
   

C#

 
GeneralRe: Multilingua virtual keyboard Pin
kelkeel7-May-16 23:59
kelkeel7-May-16 23:59 
GeneralRe: Multilingua virtual keyboard Pin
OriginalGriff8-May-16 0:15
mveOriginalGriff8-May-16 0:15 
GeneralRe: Multilingua virtual keyboard Pin
Peter_in_27808-May-16 12:00
professionalPeter_in_27808-May-16 12:00 
GeneralRe: Multilingua virtual keyboard Pin
Mycroft Holmes8-May-16 22:32
professionalMycroft Holmes8-May-16 22:32 
GeneralRe: Multilingua virtual keyboard Pin
kelkeel8-May-16 23:04
kelkeel8-May-16 23:04 
GeneralRe: Multilingua virtual keyboard Pin
kelkeel8-May-16 17:37
kelkeel8-May-16 17:37 
AnswerRe: Multilingua virtual keyboard Pin
Bernhard Hiller8-May-16 20:48
Bernhard Hiller8-May-16 20:48 
QuestionOverloading default member in a C# class Pin
Kenneth Haugland7-May-16 19:25
mvaKenneth Haugland7-May-16 19:25 
So I basically have a Complex Matrix class like so:
C#
public struct ComplexMatrix
{
    private int Rows;
    private int Cols;

    private Complex[,] matrix;
    public ComplexMatrix(int Rows, int Cols)
    {
        this.Rows = Rows;
        this.Cols = Cols;
        Complex[,] temp = new Complex[Rows, Cols];
        this.matrix = temp;
        for (int i = 0; i <= Rows - 1; i++)
        {
            for (int j = 0; j <= Cols - 1; j++)
            {
                matrix[i, j] = new Complex(0, 0);
            }
        }
    }

    public Complex this[int Row, int Col]
    {
        get { return matrix[Row, Col]; }
        set { matrix[Row, Col] = value;}
    }
...

However, Im a bit lazy so I would really like to set matrix items as follows:
MyMatrix[1, 1] = new Complex(1, 0);
MyMatrix[0, 1] = 1;
MyMatrix[1, 0] = 5d;

But I found no easy way of doing this. I basically want the setter of the property to be able to take an object, but the get function will always return a Complex.

I could of curse do this:
C#
public object this[int Row, int Col]
{
    get { return matrix[Row, Col]; }
    set
    {
        if (value is Complex)
        {
            matrix[Row, Col] = (Complex)value;

        }
        else if (value is double)
        {
            matrix[Row, Col] = new Complex((double)value, 0);
        }
        else if (value is int)
        {
            matrix[Row, Col] = new Complex((double)((int)value), 0);
        }
        else
        {
            throw new NotSupportedException("Not supported");
        }

    }
}

But that is really cumbersome when you want to get the value. Is there any tricks I could use to make this work properly?
AnswerRe: Overloading default member in a C# class Pin
Kenneth Haugland7-May-16 20:34
mvaKenneth Haugland7-May-16 20:34 
GeneralRe: Overloading default member in a C# class Pin
Peter_in_27807-May-16 20:50
professionalPeter_in_27807-May-16 20:50 
AnswerRe: Overloading default member in a C# class Pin
BillWoodruff8-May-16 5:18
professionalBillWoodruff8-May-16 5:18 
GeneralRe: Overloading default member in a C# class Pin
Kenneth Haugland8-May-16 6:21
mvaKenneth Haugland8-May-16 6:21 
GeneralRe: Overloading default member in a C# class Pin
BillWoodruff8-May-16 18:41
professionalBillWoodruff8-May-16 18:41 
QuestionICloneable class with strings Pin
WorkOnlineClick2Wealth7-May-16 18:44
WorkOnlineClick2Wealth7-May-16 18:44 
AnswerRe: ICloneable class with strings Pin
OriginalGriff7-May-16 21:09
mveOriginalGriff7-May-16 21:09 
GeneralRe: ICloneable class with strings Pin
WorkOnlineClick2Wealth8-May-16 5:00
WorkOnlineClick2Wealth8-May-16 5:00 
GeneralRe: ICloneable class with strings Pin
OriginalGriff8-May-16 5:10
mveOriginalGriff8-May-16 5:10 
GeneralRe: ICloneable class with strings Pin
WorkOnlineClick2Wealth8-May-16 6:07
WorkOnlineClick2Wealth8-May-16 6:07 
GeneralRe: ICloneable class with strings Pin
Richard Deeming9-May-16 1:50
mveRichard Deeming9-May-16 1:50 
AnswerRe: ICloneable class with strings Pin
DaveAuld8-May-16 5:37
professionalDaveAuld8-May-16 5:37 
GeneralRe: ICloneable class with strings Pin
WorkOnlineClick2Wealth8-May-16 5:46
WorkOnlineClick2Wealth8-May-16 5:46 
QuestionC# chart library with interactive elements drawing Pin
WallaceCheshire7-May-16 3:41
WallaceCheshire7-May-16 3:41 
AnswerRe: C# chart library with interactive elements drawing Pin
Ravi Bhavnani7-May-16 18:30
professionalRavi Bhavnani7-May-16 18:30 
AnswerRe: C# chart library with interactive elements drawing Pin
Kenneth Haugland7-May-16 18:31
mvaKenneth Haugland7-May-16 18:31 
QuestionWinForms issues: (partial rant, partial sharing, totally a request for opinions, comments) Pin
BillWoodruff7-May-16 2:21
professionalBillWoodruff7-May-16 2:21 

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.