I have windows form with one textbox(Pname) and one button.
I have one class by name Player with no constructor.
When user enters text inside textbox (e.g. John) and clicks button, system will create and an instance of a class Player with name of an object as John.
Your question is not very clear but I interpret that you want your Player class to store a name, that will be supplied by the user.
In that case, you need to add a property of string type named
Nameto your Player class, and when the user clicks the button, you create a new instance of Player (you can even if you don’t explicitly define a constructor), and set the property from the value of the textbox. For example, you would define the class like this:and in the event handler for the button click (assuming your textbox is named
theTextBox):