Click here to Skip to main content
15,921,530 members
Home / Discussions / C#
   

C#

 
GeneralRe: Which is more correct? Pin
Bardy8517-Jan-10 9:31
Bardy8517-Jan-10 9:31 
GeneralRe: Which is more correct? Pin
Luc Pattyn17-Jan-10 9:32
sitebuilderLuc Pattyn17-Jan-10 9:32 
Question[StructLayout(LayoutKind.Sequential)] Pin
3bood.ghzawi17-Jan-10 5:31
3bood.ghzawi17-Jan-10 5:31 
AnswerRe: [StructLayout(LayoutKind.Sequential)] Pin
Luc Pattyn17-Jan-10 5:43
sitebuilderLuc Pattyn17-Jan-10 5:43 
AnswerRe: [StructLayout(LayoutKind.Sequential)] Pin
0x3c017-Jan-10 5:45
0x3c017-Jan-10 5:45 
AnswerRe: [StructLayout(LayoutKind.Sequential)] Pin
dan!sh 17-Jan-10 6:12
professional dan!sh 17-Jan-10 6:12 
AnswerRe: [StructLayout(LayoutKind.Sequential)] Pin
harold aptroot17-Jan-10 6:28
harold aptroot17-Jan-10 6:28 
AnswerRe: [StructLayout(LayoutKind.Sequential)] Pin
DaveyM6917-Jan-10 7:32
professionalDaveyM6917-Jan-10 7:32 
It's commonly used when using external C/C++ dlls (PInvoke).

When a structure is being passed as a parameter to an external function then the called C/C++ function needs to know exactly where to find the relavent parts of the structure in memory. It does this using byte offsets from the start address (pointer) of the struct.

Imagine you had this structure
public struct MyStruct
{
    public byte a;
    public int b;
}
Without specifying the LayoutKind, this could end up being layed out in memory with b first. This would be catastrophic for the external function as it would assume the fields to be layed out in sequence - so with a first. As a result the data retrieved from memory would be incorrect. To make sure that the sequence of fields is preserved, we use LayoutKind.Sequential.

Another common one is LayoutKind.Explicit (most commonly when used with C/C++ unions). Here you explicitly state the offset for each field using the FieldOffset attribute.

Dave

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus)

QuestionExtend BindingSource with a Dirty property and Dirty changed Event Pin
ArjenGroeneveld17-Jan-10 5:20
ArjenGroeneveld17-Jan-10 5:20 
AnswerRe: Extend BindingSource with a Dirty property and Dirty changed Event Pin
Eddy Vluggen17-Jan-10 10:11
professionalEddy Vluggen17-Jan-10 10:11 
GeneralRe: Extend BindingSource with a Dirty property and Dirty changed Event Pin
ArjenGroeneveld17-Jan-10 10:38
ArjenGroeneveld17-Jan-10 10:38 
GeneralRe: Extend BindingSource with a Dirty property and Dirty changed Event Pin
Eddy Vluggen17-Jan-10 13:44
professionalEddy Vluggen17-Jan-10 13:44 
GeneralRe: Extend BindingSource with a Dirty property and Dirty changed Event Pin
ArjenGroeneveld17-Jan-10 21:24
ArjenGroeneveld17-Jan-10 21:24 
GeneralRe: Extend BindingSource with a Dirty property and Dirty changed Event Pin
Eddy Vluggen18-Jan-10 11:12
professionalEddy Vluggen18-Jan-10 11:12 
GeneralRe: Extend BindingSource with a Dirty property and Dirty changed Event Pin
sarapkamikazee1524-Aug-10 6:05
sarapkamikazee1524-Aug-10 6:05 
QuestionEmpty rows in daatagrid Pin
tasossty17-Jan-10 4:50
tasossty17-Jan-10 4:50 
AnswerRe: Empty rows in daatagrid Pin
Eddy Vluggen17-Jan-10 9:29
professionalEddy Vluggen17-Jan-10 9:29 
QuestionC# C++ Java performance comparison Pin
devvvy17-Jan-10 3:47
devvvy17-Jan-10 3:47 
AnswerRe: C# C++ Java performance comparison Pin
EliottA17-Jan-10 4:08
EliottA17-Jan-10 4:08 
AnswerRe: C# C++ Java performance comparison Pin
Luc Pattyn17-Jan-10 4:33
sitebuilderLuc Pattyn17-Jan-10 4:33 
AnswerRe: C# C++ Java performance comparison Pin
N a v a n e e t h17-Jan-10 4:34
N a v a n e e t h17-Jan-10 4:34 
AnswerRe: C# C++ Java performance comparison Pin
harold aptroot17-Jan-10 4:53
harold aptroot17-Jan-10 4:53 
GeneralRe: C# C++ Java performance comparison Pin
devvvy19-Jan-10 19:14
devvvy19-Jan-10 19:14 
GeneralRe: C# C++ Java performance comparison Pin
harold aptroot20-Jan-10 1:17
harold aptroot20-Jan-10 1:17 
Questionerrors pls help..... Pin
djsproject17-Jan-10 2:02
djsproject17-Jan-10 2:02 

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.