struct - Structure Generics in C# -


Please, help me with this problem:

I try to define a structure like this I am:

  Unprotected communities sNodo < T & gt; {Public T information; Public sNodo & lt; T & gt; * SIzq;}  

But I get this error: Can not find address of a managed type sNodo's address, size, or declare an indicator,

How can I fix this? I'm trying to create a "normal" stack using dynamic memory.

Thank you for your attention

If you need all the one Generic stack is required, you do not need unsafe just use the normal C # language:

  class stacknode  

What do you really feel that you need unsafe ?

Perhaps you are thinking that you need an indicator because otherwise your type data can not be the same type of second instance as a member. Indeed, in C # if you try to:

  struct foo {int data; Fu next; }  

... The C # compiler will complain about the circular structure references and refuse to compile your code (if you do not know why to do this, know this Try to see how many

but if you try to do the same thing with the class keyword:

  class bar {int data; Next time;}  

... everything works! If you come from C ++ background, where classes and strokes

The secret is that in C #, the values ​​of stratcits are semantic, whereas the references to classes are economics. C ++, the above two Definitions are most similar:

  square fu {int data; fu next; // is not compiled in C ++} class bar {int data; times * next; // but it OK.}  

This C ++ code is not exactly exactly the same, but you can find a bug Iadi should consider what is expected.

The bottom line: If you're just learning C #, do not use structs; They can do everything, classes can do even once you understand C # semantics, and are sure that price terminology structs can provide you with an executable benefit, and make sure that performance benefits are actually Important for your app, go ahead and use them


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -