hi I'm learning c# Let's say I have this class
public class BST
{
public int value;
public BST left;
public BST right;
}
what is the name for public BST left, it's look like constructor but it's not
CodePudding user response:
The syntax you have is
public BST left;
...which is declaring a field in your class whose type is BST. This value of this field will be a reference to some other BST object, or possibly itself, or possibly null.)
The closest looking thing to what you have that is actually a constructor might look like
public BST(int left) {}
...which would be a constructor for the BST class that takes a single integer argument called left.
Remember that constructors look like methods with no return type, and the name of the method matches the name of the class.
CodePudding user response:
It's a member field, just like int value.
You have a recursive data structure; a Binary Search Tree, based on the name.
looks like constructor
No. Constructors don't have a return type, and need a code body and parentheses for zero or more parameters
CodePudding user response:
Just a member of BST , not constructor , constructor like this BST() {}
