Click here to Skip to main content
15,913,722 members
Home / Discussions / C#
   

C#

 
Answer[Repost] Pin
Sascha Lefèvre13-Apr-15 1:58
professionalSascha Lefèvre13-Apr-15 1:58 
QuestionFixed delete SQL Server database records ? Pin
Member 245846712-Apr-15 18:44
Member 245846712-Apr-15 18:44 
AnswerRe: Fixed delete SQL Server database records ? Pin
OriginalGriff12-Apr-15 21:31
mveOriginalGriff12-Apr-15 21:31 
QuestionIs there any document oriented database with file store which can work both on windows and windows 8.1 phone platforms? Pin
thomas anderson11-Apr-15 22:41
thomas anderson11-Apr-15 22:41 
AnswerRe: Is there any document oriented database with file store which can work both on windows and windows 8.1 phone platforms? Pin
BillWoodruff13-Apr-15 3:59
professionalBillWoodruff13-Apr-15 3:59 
Questionnever done c# before Pin
Member 1159958411-Apr-15 12:40
Member 1159958411-Apr-15 12:40 
AnswerRe: never done c# before Pin
Sascha Lefèvre11-Apr-15 12:51
professionalSascha Lefèvre11-Apr-15 12:51 
GeneralRe: never done c# before Pin
Member 1159958411-Apr-15 13:21
Member 1159958411-Apr-15 13:21 
AnswerRe: never done c# before Pin
Richard Andrew x6411-Apr-15 13:49
professionalRichard Andrew x6411-Apr-15 13:49 
GeneralRe: never done c# before Pin
OriginalGriff11-Apr-15 20:49
mveOriginalGriff11-Apr-15 20:49 
AnswerRe: never done c# before Pin
V.12-Apr-15 21:47
professionalV.12-Apr-15 21:47 
QuestionCreating token for a web service Pin
eso0o11-Apr-15 6:49
eso0o11-Apr-15 6:49 
AnswerRe: Creating token for a web service Pin
Richard Andrew x6411-Apr-15 13:51
professionalRichard Andrew x6411-Apr-15 13:51 
GeneralRe: Creating token for a web service Pin
eso0o11-Apr-15 21:24
eso0o11-Apr-15 21:24 
GeneralRe: Creating token for a web service Pin
Sascha Lefèvre13-Apr-15 2:23
professionalSascha Lefèvre13-Apr-15 2:23 
QuestionEntity Data Model Pin
jkirkerx10-Apr-15 13:49
professionaljkirkerx10-Apr-15 13:49 
AnswerRe: Entity Data Model Pin
Dave Kreskowiak10-Apr-15 15:55
mveDave Kreskowiak10-Apr-15 15:55 
GeneralRe: Entity Data Model Pin
jkirkerx12-Apr-15 8:05
professionaljkirkerx12-Apr-15 8:05 
AnswerOk, How about this? Pin
jkirkerx12-Apr-15 13:55
professionaljkirkerx12-Apr-15 13:55 
QuestionChanging a Struct Property Value Pin
Kevin Marois10-Apr-15 11:01
professionalKevin Marois10-Apr-15 11:01 
AnswerRe: Changing a Struct Property Value PinPopular
harold aptroot10-Apr-15 12:31
harold aptroot10-Apr-15 12:31 
Coder For Hire wrote:
I'm not trying to change the struct, I'm try to change the departmentId.
That's the problem. You can change the struct, but assigning to its fields (no matter if it's with a property or not) would do nothing (and is banned because it is always a bug).

Remember that properties are just syntactic sugar for get and set methods. You can see this in effect in a decompiler (you may have to mess with settings). Using TheDepartment in a context where it is read from (as you do here) then you're really calling a get-method that returns it. So it's a copy. You're making a copy, calling a set-method on it, then the copy disappears and really nothing has happened at all (unless the properties have side effects). At least, that's what you would be doing if it wasn't an error to write this. That's a sort of unofficial way to look at it though, properties and methods do act differently, for example if you emulate a property using your own getter and setter then you wouldn't get this compile error (you'd get the useless behaviour I described above).

This "weird difference" between fields and properties also exists between elements of an array and indexers (in particular this means changing an array of structs to List<T> does not always work).

To quote the spec,
ECMA 334, §14.5.4 Member access:
... if E is a property or indexer access, then the value of the property or indexer access is obtained
(§14.1.1) and E is reclassified as a value.
This says that TheDepartment is a value, and
ECMA 334, §18.3.3 Assignment:
When a property or indexer of a struct is the target of an assignment, the instance expression associated with
the property or indexer access shall be classified as a variable. If the instance expression is classified as a
value, a compile-time error occurs. This is described in further detail in §14.14.1.
says that if the target of assignment is a property of a struct and the instance is a value, then it's an error. So, DepartmentId cannot be the target of assignment here.
AnswerRe: Changing a Struct Property Value Pin
OriginalGriff10-Apr-15 22:03
mveOriginalGriff10-Apr-15 22:03 
AnswerRe: Changing a Struct Property Value Pin
BillWoodruff10-Apr-15 22:53
professionalBillWoodruff10-Apr-15 22:53 
GeneralRe: Changing a Struct Property Value Pin
Richard Deeming13-Apr-15 1:31
mveRichard Deeming13-Apr-15 1:31 
GeneralRe: Changing a Struct Property Value Pin
BillWoodruff13-Apr-15 1:49
professionalBillWoodruff13-Apr-15 1:49 

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.