Click here to Skip to main content
15,921,577 members
Home / Discussions / C#
   

C#

 
AnswerRe: java.security.PrivateKey Pin
Richard MacCutchan30-Dec-14 0:54
mveRichard MacCutchan30-Dec-14 0:54 
QuestionI can not apply Drag Drop in this case Pin
VisualLive29-Dec-14 23:14
VisualLive29-Dec-14 23:14 
AnswerRe: I can not apply Drag Drop in this case Pin
Richard MacCutchan30-Dec-14 0:53
mveRichard MacCutchan30-Dec-14 0:53 
GeneralRe: I can not apply Drag Drop in this case Pin
VisualLive30-Dec-14 14:59
VisualLive30-Dec-14 14:59 
QuestionHow to organize this data Pin
turbosupramk329-Dec-14 8:14
turbosupramk329-Dec-14 8:14 
AnswerRe: How to organize this data Pin
Pete O'Hanlon29-Dec-14 8:53
mvePete O'Hanlon29-Dec-14 8:53 
GeneralRe: How to organize this data Pin
PIEBALDconsult29-Dec-14 9:07
mvePIEBALDconsult29-Dec-14 9:07 
AnswerRe: How to organize this data Pin
BillWoodruff29-Dec-14 9:20
professionalBillWoodruff29-Dec-14 9:20 
I've written this type of Class so many times I think I could write it half-asleep Smile | :)
C#
// required
using System.Collections.Generic;
using System.Linq;

namespace YetAnother
{
    public class PointyPoint
    {
        public int X { set; get; }
        public int Y { set; get; }
        public double Value { set; get; }

        public PointyPoint() {}

        public PointyPoint(int x, int y, double value)
        {
            X = x;
            Y = y;
            Value = value;
        }
    }

    public enum PointySortType
    {
        PSortAscendingX,
        PSortAscendingY,
        PSortDescendingX,
        PSortDescendingY,
        PSortAscendingValue,
        PSortDescendingValue
    }

    public class PointyListClass : List<PointyPoint>
    {
        public PointyListClass() {}

        public List<PointyPoint> PointySortedBy(PointySortType pSType, PointyListClass pointyList)
        {
            // throw error ?
            if (pointyList == null || pointyList.Count == 1) return null;

            switch (pSType)
            {
                case PointySortType.PSortAscendingX:
                {
                    return pointyList.OrderBy(pointy => pointy.X).ToList();
                }
                case PointySortType.PSortAscendingY:
                {
                    return pointyList.OrderBy(pointy => pointy.Y).ToList();
                }
                case PointySortType.PSortDescendingX:
                {
                    return pointyList.OrderByDescending(pointy => pointy.X).ToList();
                }
                case PointySortType.PSortDescendingY:
                {
                    return pointyList.OrderByDescending(pointy => pointy.Y).ToList();
                }
                case PointySortType.PSortAscendingValue:
                {
                    return pointyList.OrderBy(pointy => pointy.Value).ToList();
                }
                case PointySortType.PSortDescendingValue:
                {
                    return pointyList.OrderByDescending(pointy => pointy.Value).ToList();
                }
            }

            // throw error ?
            return null;
        }
    }
}

// test it in some appropriate context

private void SomeButton_Click(object sender, EventArgs e)
{
    PointyListClass pointyList = new PointyListClass
    {
        {new PointyPoint(100,400,199.99)},
        {new PointyPoint(200,300,12.43)},
        {new PointyPoint(300,200,-12333)},
        {new PointyPoint(400,100,345.93)},
    };

    var pointyXAscending = pointyList.PointySortedBy(PointySortType.PSortAscendingX, pointyList).ToList();
    var pointyYAscending = pointyList.PointySortedBy(PointySortType.PSortAscendingY, pointyList).ToList();

    var pointyXDescending = pointyList.PointySortedBy(PointySortType.PSortDescendingX, pointyList).ToList();
    var pointyDescending = pointyList.PointySortedBy(PointySortType.PSortDescendingY, pointyList).ToList();

    var pointyValueAscending = pointyList.PointySortedBy(PointySortType.PSortAscendingValue, pointyList).ToList();
    var pointyValueDescending = pointyList.PointySortedBy(PointySortType.PSortDescendingValue, pointyList).ToList();
}

«A man will be imprisoned in a room with a door that's unlocked and opens inwards ... as long as it does not occur to him to pull rather than push»  Wittgenstein

GeneralRe: How to organize this data Pin
PIEBALDconsult29-Dec-14 10:04
mvePIEBALDconsult29-Dec-14 10:04 
GeneralRe: How to organize this data Pin
BillWoodruff29-Dec-14 12:12
professionalBillWoodruff29-Dec-14 12:12 
GeneralRe: How to organize this data Pin
SledgeHammer0129-Dec-14 10:50
SledgeHammer0129-Dec-14 10:50 
GeneralRe: How to organize this data Pin
BillWoodruff29-Dec-14 12:11
professionalBillWoodruff29-Dec-14 12:11 
GeneralRe: How to organize this data Pin
SledgeHammer0129-Dec-14 12:28
SledgeHammer0129-Dec-14 12:28 
GeneralRe: How to organize this data Pin
BillWoodruff29-Dec-14 14:18
professionalBillWoodruff29-Dec-14 14:18 
GeneralRe: How to organize this data Pin
SledgeHammer0129-Dec-14 14:58
SledgeHammer0129-Dec-14 14:58 
GeneralRe: How to organize this data Pin
BillWoodruff29-Dec-14 23:44
professionalBillWoodruff29-Dec-14 23:44 
GeneralRe: How to organize this data Pin
SledgeHammer0130-Dec-14 4:13
SledgeHammer0130-Dec-14 4:13 
GeneralRe: How to organize this data Pin
PIEBALDconsult29-Dec-14 13:07
mvePIEBALDconsult29-Dec-14 13:07 
GeneralRe: How to organize this data Pin
BillWoodruff29-Dec-14 23:15
professionalBillWoodruff29-Dec-14 23:15 
GeneralRe: How to organize this data Pin
SledgeHammer0130-Dec-14 4:17
SledgeHammer0130-Dec-14 4:17 
GeneralRe: How to organize this data Pin
BillWoodruff30-Dec-14 23:42
professionalBillWoodruff30-Dec-14 23:42 
GeneralRe: How to organize this data Pin
PIEBALDconsult30-Dec-14 15:29
mvePIEBALDconsult30-Dec-14 15:29 
GeneralRe: How to organize this data Pin
BillWoodruff30-Dec-14 23:53
professionalBillWoodruff30-Dec-14 23:53 
GeneralMessage Closed Pin
29-Dec-14 2:32
Marvic Grima29-Dec-14 2:32 
Questionserial port CreateFile in c# Pin
Member 1114321929-Dec-14 2:16
Member 1114321929-Dec-14 2:16 

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.