Click here to Skip to main content
16,005,236 members
Home / Discussions / C#
   

C#

 
QuestionHelp understanding value types Pin
-Rowan-13-Dec-05 23:45
-Rowan-13-Dec-05 23:45 
AnswerRe: Help understanding value types Pin
GDavy14-Dec-05 0:06
GDavy14-Dec-05 0:06 
AnswerRe: Help understanding value types Pin
xtroll14-Dec-05 0:13
xtroll14-Dec-05 0:13 
AnswerRe: Help understanding value types Pin
Vikram A Punathambekar14-Dec-05 1:25
Vikram A Punathambekar14-Dec-05 1:25 
GeneralRe: Help understanding value types Pin
S. Senthil Kumar14-Dec-05 6:29
S. Senthil Kumar14-Dec-05 6:29 
GeneralRe: Help understanding value types Pin
Vikram A Punathambekar14-Dec-05 16:27
Vikram A Punathambekar14-Dec-05 16:27 
AnswerRe: Help understanding value types Pin
Guffa14-Dec-05 1:33
Guffa14-Dec-05 1:33 
AnswerRe: Help understanding value types Pin
S. Senthil Kumar14-Dec-05 6:35
S. Senthil Kumar14-Dec-05 6:35 
-Rowan- wrote:
What is the best way to allocate a ValueType that has nothing stored in it if I can't null it?

If you're the author of the type, you could have a special static property to do that, something like
struct MyStruct
{
   static MyStruct Empty
   {
      return new MyStruct(<Some Invalid Value>);
   }
}


-Rowan- wrote:
If I use the first example does that mean that the Point is actually allocated? If so does it have random data in it? This would imply that the two options above cost exactly the same processor wise.

Almost but not quite true. Your first example does result in a stack allocation. The compiler forces you to initialize all fields before using the instance, so you won't run into random data.

The second line of code causes the compiler to emit a .initobj IL instruction, which results in all fields in the struct being initialized to their default values.

Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
QuestionVariable array length Pin
Genbox13-Dec-05 23:26
Genbox13-Dec-05 23:26 
AnswerRe: Variable array length Pin
Guffa14-Dec-05 1:35
Guffa14-Dec-05 1:35 
GeneralRe: Variable array length Pin
mcljava15-Dec-05 5:29
mcljava15-Dec-05 5:29 
QuestionMoving problems in Extended Columns Pin
Greeky13-Dec-05 23:22
Greeky13-Dec-05 23:22 
QuestionDataGridDateTimeExtendedColumn Problem Pin
Greeky13-Dec-05 23:17
Greeky13-Dec-05 23:17 
QuestionAdd parameters Pin
mehrdadc4813-Dec-05 23:10
mehrdadc4813-Dec-05 23:10 
AnswerRe: Add parameters Pin
freshonlineMax13-Dec-05 23:32
freshonlineMax13-Dec-05 23:32 
AnswerRe: Add parameters Pin
mehrdadc4814-Dec-05 0:01
mehrdadc4814-Dec-05 0:01 
QuestionHow to validate the URL ? Pin
P. Gnana Prakash13-Dec-05 23:08
P. Gnana Prakash13-Dec-05 23:08 
QuestiondataGrid in WIndows Pin
Mahi.Ragava13-Dec-05 22:46
Mahi.Ragava13-Dec-05 22:46 
AnswerRe: dataGrid in WIndows Pin
Mahi.Ragava14-Dec-05 0:49
Mahi.Ragava14-Dec-05 0:49 
Questionlink finder in source code with regex Pin
fetras13-Dec-05 22:43
fetras13-Dec-05 22:43 
AnswerRe: link finder in source code with regex Pin
MarcelErz13-Dec-05 23:48
MarcelErz13-Dec-05 23:48 
QuestionAutomation Addin for Excel with .Net 2.0 Pin
Mario Peischl13-Dec-05 22:40
Mario Peischl13-Dec-05 22:40 
Questiondesign report in c# code editor? Pin
dinh van hai13-Dec-05 22:11
dinh van hai13-Dec-05 22:11 
QuestionAdding a macro to my Word doc from C# Pin
Hovik Melkomian13-Dec-05 22:07
Hovik Melkomian13-Dec-05 22:07 
Questionusing &quot; in a string variable Pin
fetras13-Dec-05 21:47
fetras13-Dec-05 21:47 

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.