Click here to Skip to main content
15,905,504 members
Home / Discussions / C#
   

C#

 
GeneralRe: WinForm launching a console application Pin
Dave Kreskowiak3-Feb-21 7:13
mveDave Kreskowiak3-Feb-21 7:13 
GeneralRe: WinForm launching a console application Pin
Gerry Schmitz3-Feb-21 7:28
mveGerry Schmitz3-Feb-21 7:28 
AnswerRe: WinForm launching a console application Pin
Dave Kreskowiak2-Feb-21 18:40
mveDave Kreskowiak2-Feb-21 18:40 
AnswerRe: WinForm launching a console application Pin
OriginalGriff2-Feb-21 19:48
mveOriginalGriff2-Feb-21 19:48 
GeneralRe: WinForm launching a console application Pin
trønderen3-Feb-21 3:58
trønderen3-Feb-21 3:58 
GeneralRe: WinForm launching a console application Pin
OriginalGriff3-Feb-21 5:13
mveOriginalGriff3-Feb-21 5:13 
AnswerRe: WinForm launching a console application Pin
TimWallace8-Feb-21 18:03
TimWallace8-Feb-21 18:03 
QuestionHow to sum up values of duplicate keys in a dictionary? Pin
Alex Dunlop2-Feb-21 6:37
Alex Dunlop2-Feb-21 6:37 
I have 5 column in a spreadsheet (DevExpress spreadsheet). The first four columns are string values. The fifth column is integer (numeric). I joined those first four columns and put it as KEYs in a list, then collected the fifth column entries as VALUEs in an another list. I used these two lists to create a dictionary.
Now, I want to sum values related to each duplicate keys. As you now, dictionary object throw an exception for duplicate keys. How can I sum those values related to each duplicate keys?
I tried this:
C#
IWorkbook workbook = spreadsheetControl.Document;
            Worksheet worksheet = workbook.Worksheets.ActiveWorksheet;
            CellRange range = worksheet.GetDataRange();
            int LastRow = range.BottomRowIndex;
            var keys = new List<string>();
            var values = new List<int>();

            for (int i = 0; i < LastRow + 1; i++)
            {
                keys.Add(string.Join(",", worksheet.Cells[i, 0].DisplayText, worksheet.Cells[i, 1].DisplayText,
                    worksheet.Cells[i, 2].DisplayText, worksheet.Cells[i, 3].DisplayText));
                values.Add((int)worksheet.Cells[i, 4].Value.NumericValue);
            }
            var mydic = new Dictionary<string, int>();
            for (int i = 0; i < keys.Count; i++)
            {
                try
                {
                    mydic.Add(keys[i], values[i]);
                }
                catch (Exception)
                {
                    if (mydic.ContainsKey("f,a,r,d") == true)
                    {
                        MessageBox.Show("Duplicate");
                    }
                }
            }

I need to replace
C#
if (mydic.ContainsKey("f,a,r,d") == true)
                    {
                        MessageBox.Show("Duplicate");
                    }
with another code. Confused | :confused:

modified 2-Feb-21 12:48pm.

AnswerRe: How to sum up values of duplicate keys in a dictionary? Pin
Dave Kreskowiak2-Feb-21 12:35
mveDave Kreskowiak2-Feb-21 12:35 
GeneralRe: How to sum up values of duplicate keys in a dictionary? Pin
Alex Dunlop3-Feb-21 5:39
Alex Dunlop3-Feb-21 5:39 
GeneralRe: How to sum up values of duplicate keys in a dictionary? Pin
Dave Kreskowiak3-Feb-21 6:36
mveDave Kreskowiak3-Feb-21 6:36 
GeneralRe: How to sum up values of duplicate keys in a dictionary? Pin
Alex Dunlop3-Feb-21 6:50
Alex Dunlop3-Feb-21 6:50 
QuestionTrying to use and condition in Linq Query with join and on C# Pin
simpledeveloper1-Feb-21 21:04
simpledeveloper1-Feb-21 21:04 
QuestionWhat queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
arnold_w29-Jan-21 22:58
arnold_w29-Jan-21 22:58 
AnswerRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
Richard MacCutchan29-Jan-21 23:19
mveRichard MacCutchan29-Jan-21 23:19 
GeneralRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
arnold_w30-Jan-21 0:31
arnold_w30-Jan-21 0:31 
GeneralRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
Richard MacCutchan30-Jan-21 0:32
mveRichard MacCutchan30-Jan-21 0:32 
AnswerRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
OriginalGriff29-Jan-21 23:25
mveOriginalGriff29-Jan-21 23:25 
GeneralRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
arnold_w30-Jan-21 1:00
arnold_w30-Jan-21 1:00 
GeneralRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
OriginalGriff30-Jan-21 1:17
mveOriginalGriff30-Jan-21 1:17 
GeneralRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
arnold_w30-Jan-21 1:27
arnold_w30-Jan-21 1:27 
GeneralRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
OriginalGriff30-Jan-21 1:58
mveOriginalGriff30-Jan-21 1:58 
GeneralRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
arnold_w30-Jan-21 2:02
arnold_w30-Jan-21 2:02 
GeneralRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
OriginalGriff30-Jan-21 2:39
mveOriginalGriff30-Jan-21 2:39 
GeneralRe: What queuing technique and GUI component should I choose for my multi-comport, receive-only terminal software? Pin
arnold_w30-Jan-21 2:50
arnold_w30-Jan-21 2:50 

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.