How to create a node in c# -
i new c# , switched c c#. want equivalent of c c#. same have in c this:
temp = (struct node*)malloc(sizeof(struct node)); where node is:
struct node { unsigned int symbol ; int freq; struct node * next, * left, * right; } and in c# have used class instead of struct. tried way:
node temp = new node(); where node same except it's class , used public (i sure that's correct). please me if wrong ? correctly create node equivalent created using malloc() ?
your class should like
public class node { public unsigned int symbol; public int freq; public node next; public node left; public node right; } if assign next, left, , right similar to
node root = new node(); root.next = new node(); you see behavior similar doing in c.
storage automatically managed runtime, there no explicit calls equivalents of malloc or free. happens behind scenes.
also, general rule not use pointers in c#. while can if mark code unsafe, there few instances unsafe code right path c# app.
note: example uses public access class , fields. may want restrict based on specific use.
Comments
Post a Comment