Click here to Skip to main content
15,895,799 members
Home / Discussions / C#
   

C#

 
QuestionPython httpServ.request in C# - HttpWebRequest ? Pin
Member 1400288230-Sep-18 9:59
Member 1400288230-Sep-18 9:59 
AnswerRe: Python httpServ.request in C# - HttpWebRequest ? Pin
Richard MacCutchan30-Sep-18 21:08
mveRichard MacCutchan30-Sep-18 21:08 
GeneralRe: Python httpServ.request in C# - HttpWebRequest ? Pin
Member 140028821-Oct-18 11:26
Member 140028821-Oct-18 11:26 
QuestionSwitching 2 Variables Pin
Member 1400283730-Sep-18 8:19
Member 1400283730-Sep-18 8:19 
AnswerRe: Switching 2 Variables Pin
Dave Kreskowiak30-Sep-18 8:53
mveDave Kreskowiak30-Sep-18 8:53 
GeneralRe: Switching 2 Variables Pin
Member 1400283730-Sep-18 10:55
Member 1400283730-Sep-18 10:55 
AnswerRe: Switching 2 Variables Pin
BillWoodruff14-Oct-18 15:35
professionalBillWoodruff14-Oct-18 15:35 
QuestionFundamental misunderstanding of structs as "value" types Pin
bh_28-Sep-18 3:54
bh_28-Sep-18 3:54 
Dear fellow C# programmers.

I am trying to model a command that I will send to a product. The command payload consists of:

Header   (byte)
Command  (byte)
Length   (byte)
Data     (byte[])
Checksum (byte[2])


Now, the values for the header and command are always static for a particular function. The user only needs to change the data directly.
Indirectly, the Length and Checksum properties will change, but I have written methods which automatically calculate these upon any change of Data.

My idea is I can define a set of these commands as a template to accommodate all the different functions. The user can then use the commands, setting their own data as necessary.

When a user "uses" a command, I don't want them to change the Data property in the template commands. I want the user to create a clone of the command, such that when they change the Data property then these changes are only present in their local instance of the command.

I thought I understood that I could model the command as a struct, so that each command would be a "value type".
Then, when I do:

C#
Command DestroyProduct = new Command(byte header, byte command, byte[] data);
...
...
Command LetOutMagicSmoke = new Command();
LetOutMagicSmoke = DestroyProduct;
LetOutMagicSmoke.Data = new byte[] {0x00, 0x01, etc};


Then the changes to Data are only present in LetOutMagicSmoke and not in DestroyProduct.

This is not how the code is behaving. Instead, changes made to LetOutMagicSmoke.Data are also made to the template command.

The only explanation I can think of is that since byte[] is a reference type, then when I say LetOutMagicSmoke = DestroyProduct; the byte arrays are copied by reference.

This is not the behaviour I want!

My next idea is to put some code in the 'getter' for the Command which iterates over the byte array, extracting out all the bytes, and then putting them into a new byte array, before returning the command to the user.

I haven't implemented that yet but I would like to get my understanding of this issue hashed out first.
Have I understood what is going on correctly? Is my next idea the best way forwards?

Many thanks.
AnswerRe: Fundamental misunderstanding of structs as "value" types Pin
OriginalGriff28-Sep-18 4:12
mveOriginalGriff28-Sep-18 4:12 
GeneralRe: Fundamental misunderstanding of structs as "value" types Pin
bh_28-Sep-18 4:49
bh_28-Sep-18 4:49 
GeneralRe: Fundamental misunderstanding of structs as "value" types Pin
OriginalGriff28-Sep-18 4:55
mveOriginalGriff28-Sep-18 4:55 
Questionhow to create discussion forum in our asp.net application Pin
Member 1400092528-Sep-18 2:29
Member 1400092528-Sep-18 2:29 
AnswerRe: how to create discussion forum in our asp.net application Pin
Pete O'Hanlon28-Sep-18 3:24
mvePete O'Hanlon28-Sep-18 3:24 
Questionmake a design similar to windows mail in visual studio Pin
erdalczr28-Sep-18 0:46
erdalczr28-Sep-18 0:46 
AnswerRe: make a design similar to windows mail in visual studio Pin
OriginalGriff28-Sep-18 2:35
mveOriginalGriff28-Sep-18 2:35 
GeneralRe: make a design similar to windows mail in visual studio Pin
Richard MacCutchan28-Sep-18 3:29
mveRichard MacCutchan28-Sep-18 3:29 
GeneralRe: make a design similar to windows mail in visual studio Pin
OriginalGriff28-Sep-18 3:54
mveOriginalGriff28-Sep-18 3:54 
QuestionUploading a large Excel file using Entity Framework and Stored Procedure Call Pin
simpledeveloper27-Sep-18 8:40
simpledeveloper27-Sep-18 8:40 
AnswerRe: Uploading a large Excel file using Entity Framework and Stored Procedure Call Pin
Dave Kreskowiak27-Sep-18 9:50
mveDave Kreskowiak27-Sep-18 9:50 
GeneralRe: Uploading a large Excel file using Entity Framework and Stored Procedure Call Pin
simpledeveloper27-Sep-18 10:11
simpledeveloper27-Sep-18 10:11 
GeneralRe: Uploading a large Excel file using Entity Framework and Stored Procedure Call Pin
Member 140028821-Oct-18 0:10
Member 140028821-Oct-18 0:10 
GeneralRe: Uploading a large Excel file using Entity Framework and Stored Procedure Call Pin
Dave Kreskowiak1-Oct-18 4:20
mveDave Kreskowiak1-Oct-18 4:20 
GeneralRe: Uploading a large Excel file using Entity Framework and Stored Procedure Call Pin
Member 140028821-Oct-18 11:27
Member 140028821-Oct-18 11:27 
GeneralRe: Uploading a large Excel file using Entity Framework and Stored Procedure Call Pin
simpledeveloper1-Oct-18 13:30
simpledeveloper1-Oct-18 13:30 
GeneralRe: Uploading a large Excel file using Entity Framework and Stored Procedure Call Pin
Dave Kreskowiak1-Oct-18 15:52
mveDave Kreskowiak1-Oct-18 15:52 

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.