Click here to Skip to main content
15,920,111 members
Home / Discussions / C#
   

C#

 
AnswerRe: dictionary/list help needed Pin
Richard MacCutchan6-Oct-13 5:09
mveRichard MacCutchan6-Oct-13 5:09 
GeneralRe: dictionary/list help needed Pin
yoni.kess6-Oct-13 5:20
yoni.kess6-Oct-13 5:20 
GeneralRe: dictionary/list help needed Pin
Richard MacCutchan6-Oct-13 5:45
mveRichard MacCutchan6-Oct-13 5:45 
GeneralRe: dictionary/list help needed Pin
yoni.kess6-Oct-13 5:51
yoni.kess6-Oct-13 5:51 
GeneralRe: dictionary/list help needed Pin
Richard MacCutchan6-Oct-13 6:22
mveRichard MacCutchan6-Oct-13 6:22 
GeneralRe: dictionary/list help needed Pin
yoni.kess6-Oct-13 10:10
yoni.kess6-Oct-13 10:10 
GeneralRe: dictionary/list help needed Pin
Richard MacCutchan6-Oct-13 20:44
mveRichard MacCutchan6-Oct-13 20:44 
AnswerRe: dictionary/list help needed Pin
BillWoodruff6-Oct-13 16:58
professionalBillWoodruff6-Oct-13 16:58 
Your question would be much more understandable if you put the code for button3_Click that you disclosed to Richard MacCutchan in your original post, and edited the code so only the possible problem area is shown.

If you have a field in your db that is guaranteed unique per row that you can use as a key, then using a Dictionary makes sense ... but, in this case, it appears you don't.

I'd start by modeling data structures from "inside to outside," from "atoms," to "molecules."

So, I'd define an "atomic class" that would hold only the necessary data for a single ship position measurement:
C#
public class Position
{
    public bool IsDay  { get; private set; }
    public double Latitude  { get; private set; }
    public double Longitude  { get; private set; }

    public Position(bool isDay, double latitude, double longitude)
    {
        IsDay = isDay;
        Latitude = latitude;
        Longitude = longitude;
    }

    public override string ToString()
    {
        return
            "Time: "
            + (IsDay ? "Day " : "Night ")
            + " Latitude: " + Latitude.ToString()
            + " Longitude: " + Longitude.ToString();
    }
}
I'd then move on to the question of what my final goal is here: clearly each ship is going to have a collection of instances of Position:
C#
internal class ShipPositionList : List<Position>
{
    public override string ToString()
    {
        string s = "";

        foreach (Position pos in this)
        {
            s += pos.ToString() + Environment.NewLine;
        }

        return s;
    }
}
And, finally, I'd consider what the data structure for the outermost object is:
C#
public class Ship
{
    public string ShipName { get; private set; }

    internal ShipPositionList PositionList { get; private set; }

    public Ship(string shipName)
    {
        ShipName = shipName;

        PositionList = new ShipPositionList();
    }

    public void AddPosition(bool isDay, double lati, double longi)
    {
        PositionList.Add(new Position(isDay, lati, longi));
    }

    public override string ToString()
    {
        return
            ShipName
            + Environment.NewLine
            + PositionList.ToString();
    }
}
At this point, I might well start wondering why I am writing out such an elaborate multi-class model, and start coding lean-and-mean Smile | :)

Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview

GeneralRe: dictionary/list help needed Pin
yoni.kess6-Oct-13 21:39
yoni.kess6-Oct-13 21:39 
GeneralRe: dictionary/list help needed Pin
BillWoodruff7-Oct-13 0:39
professionalBillWoodruff7-Oct-13 0:39 
QuestionEntity Framework: Primary key violation Pin
Lutosław6-Oct-13 2:55
Lutosław6-Oct-13 2:55 
AnswerRe: Entity Framework: Primary key violation Pin
Dave Kreskowiak6-Oct-13 6:28
mveDave Kreskowiak6-Oct-13 6:28 
GeneralRe: Entity Framework: Primary key violation Pin
Lutosław6-Oct-13 9:50
Lutosław6-Oct-13 9:50 
Questionupdate ConnectionString in App.config Pin
Jassim Rahma6-Oct-13 0:03
Jassim Rahma6-Oct-13 0:03 
AnswerRe: update ConnectionString in App.config Pin
OriginalGriff6-Oct-13 0:10
mveOriginalGriff6-Oct-13 0:10 
QuestionSimple cross threading question Pin
ve3tru5-Oct-13 17:55
ve3tru5-Oct-13 17:55 
AnswerRe: Simple cross threading question Pin
Abhinav S5-Oct-13 19:00
Abhinav S5-Oct-13 19:00 
GeneralRe: Simple cross threading question Pin
ve3tru6-Oct-13 16:03
ve3tru6-Oct-13 16:03 
AnswerRe: Simple cross threading question Pin
Dave Kreskowiak6-Oct-13 4:24
mveDave Kreskowiak6-Oct-13 4:24 
AnswerRe: Simple cross threading question Pin
Richard MacCutchan6-Oct-13 5:04
mveRichard MacCutchan6-Oct-13 5:04 
Questionget pixel color on image Pin
Member 102255295-Oct-13 4:51
Member 102255295-Oct-13 4:51 
AnswerRe: get pixel color on image Pin
BillWoodruff5-Oct-13 7:22
professionalBillWoodruff5-Oct-13 7:22 
AnswerRe: get pixel color on image Pin
Richard MacCutchan5-Oct-13 20:51
mveRichard MacCutchan5-Oct-13 20:51 
AnswerRe: get pixel color on image Pin
AngloThaiSolutions7-Oct-13 4:01
AngloThaiSolutions7-Oct-13 4:01 
QuestionFocus of the DevExpress DateEdit Pin
nhanlaptrinh3-Oct-13 22:10
nhanlaptrinh3-Oct-13 22:10 

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.