Click here to Skip to main content
15,885,985 members
Home / Discussions / C#
   

C#

 
GeneralRe: Best machine learning AI library to assess multiple inputs with different weights (non-linear) ? Pin
Member 978298313-Nov-17 4:59
Member 978298313-Nov-17 4:59 
GeneralRe: Best machine learning AI library to assess multiple inputs with different weights (non-linear) ? Pin
Gerry Schmitz13-Nov-17 5:01
mveGerry Schmitz13-Nov-17 5:01 
Questioncan't find the source of Collection was Modified Exception Pin
Alexander Kindel11-Nov-17 19:46
Alexander Kindel11-Nov-17 19:46 
AnswerRe: can't find the source of Collection was Modified Exception Pin
OriginalGriff11-Nov-17 20:10
mveOriginalGriff11-Nov-17 20:10 
GeneralRe: can't find the source of Collection was Modified Exception Pin
Alexander Kindel11-Nov-17 20:14
Alexander Kindel11-Nov-17 20:14 
GeneralRe: can't find the source of Collection was Modified Exception Pin
OriginalGriff11-Nov-17 20:23
mveOriginalGriff11-Nov-17 20:23 
QuestionHow to simplify my code? Pin
Member 1347915010-Nov-17 12:09
Member 1347915010-Nov-17 12:09 
AnswerRe: How to simplify my code? Pin
Afzaal Ahmad Zeeshan10-Nov-17 12:26
professionalAfzaal Ahmad Zeeshan10-Nov-17 12:26 
That does look quite ugly.

You need to start by reading at the builder pattern, to build up the objects (you had a switch statement in the constructor).Understanding and Implementing Builder Pattern in C#.

Then as for the rest of the code, I might just create a separate function to handle the types, because most of the operations are same.
C#
case 1:
    RedCard.Position.X = e.X + OffsetX;
    RedCard.Position.Y = e.Y + OffsetY;
    Table.Invalidate();
    break;
case 2:
    BlueCard.Position.X = e.X + OffsetX;
    BlueCard.Position.Y = e.Y + OffsetY;
    Table.Invalidate();
    break;
That part of the code can be rewritten to, something like this,
C#
private void updateCardPosition(Card card, int x, int y) {
    card.Position.X = x;
    card.Position.Y = y;
}

// then you call from the switch
case 1:
    updateCardPosition(RedCard);
Lastly, the Table.Invalidate(); gets called in each of the block, so you can bring it out of the switch statement.

So basically you need to rewrite the code a bit functional in nature. Otherwise your code looks fine to me, just the redundancy of the code which you have to remove.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~

QuestionUnhandled Argument Exception error in System.Drawing.dll Pin
zs6msd8-Nov-17 0:05
zs6msd8-Nov-17 0:05 
AnswerRe: Unhandled Argument Exception error in System.Drawing.dll Pin
OriginalGriff8-Nov-17 0:28
mveOriginalGriff8-Nov-17 0:28 
Questionlibrary for connecting oracle from c#form Pin
Member 135093657-Nov-17 20:04
Member 135093657-Nov-17 20:04 
AnswerRe: library for connecting oracle from c#form Pin
Pete O'Hanlon7-Nov-17 21:34
mvePete O'Hanlon7-Nov-17 21:34 
GeneralRe: library for connecting oracle from c#form Pin
Member 135093658-Nov-17 21:26
Member 135093658-Nov-17 21:26 
GeneralRe: library for connecting oracle from c#form Pin
Member 135093658-Nov-17 21:26
Member 135093658-Nov-17 21:26 
AnswerRe: library for connecting oracle from c#form Pin
Mycroft Holmes8-Nov-17 14:18
professionalMycroft Holmes8-Nov-17 14:18 
QuestionGetting Data from web : C# failed while Excel works Pin
PozzaVecia5-Nov-17 9:06
PozzaVecia5-Nov-17 9:06 
AnswerRe: Getting Data from web : C# failed while Excel works Pin
PozzaVecia5-Nov-17 9:19
PozzaVecia5-Nov-17 9:19 
QuestionWrite audio to USB Modem via COM Port Pin
ManojKumarShah20174-Nov-17 22:45
ManojKumarShah20174-Nov-17 22:45 
QuestionRe: Write audio to USB Modem via COM Port Pin
Eddy Vluggen4-Nov-17 23:34
professionalEddy Vluggen4-Nov-17 23:34 
AnswerRe: Write audio to USB Modem via COM Port Pin
OriginalGriff4-Nov-17 23:35
mveOriginalGriff4-Nov-17 23:35 
GeneralRe: Write audio to USB Modem via COM Port Pin
ManojKumarShah20175-Nov-17 0:57
ManojKumarShah20175-Nov-17 0:57 
GeneralRe: Write audio to USB Modem via COM Port Pin
OriginalGriff5-Nov-17 1:05
mveOriginalGriff5-Nov-17 1:05 
GeneralRe: Write audio to USB Modem via COM Port Pin
ManojKumarShah20175-Nov-17 2:31
ManojKumarShah20175-Nov-17 2:31 
GeneralRe: Write audio to USB Modem via COM Port Pin
OriginalGriff5-Nov-17 2:40
mveOriginalGriff5-Nov-17 2:40 
GeneralRe: Write audio to USB Modem via COM Port Pin
ManojKumarShah20175-Nov-17 3:46
ManojKumarShah20175-Nov-17 3:46 

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.