Click here to Skip to main content
16,017,922 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want do like that code in c#

C++
node=(struct student *)new(struct student);

node is pointer and i want to do that job
Posted
Updated 28-Nov-13 3:46am
v3

You don't normally use pointers in C# - you can, but only in unsafe code[^] and it is deliberatly difficult to do.

Unless you are passing data between C# and external non-.NET code, or you need serious performance tuning it is a very bad idea. use a reference instead:
C#
Student node = new Student();
And let the system sort it all out for you.
 
Share this answer
 
C#
using System.Runtime.InteropServices;

C#
node=(student *)Marshal.AllocHGlobal(sizeof(student));

this is exactly what i want and its true
 
Share this answer
 
Comments
johannesnestler 28-Nov-13 10:08am    
As OriginalGriff mentioned this is only needed in rare interop scenarios. Are you shure you are not approaching .NET with (C++) thinking? - at least for me that was very common when i came to C# from C++. If no interop is involved: declare studend as "class", it will be a reference type then and all the "pointer" things (dereferencing etc.) are managed in .NET under the hood...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900