Home > other >  how do i get my string from the class initialization?
how do i get my string from the class initialization?

Time:04-27

my class starts with

 public LateReturn(string username)
    {
        InitializeComponent();
    }

I've already tried things like string s = this.username/username

how do I get username to the class, aka how can I do string s = username

CodePudding user response:

private string user;
    public LateReturn(string username)
    {
        InitializeComponent();
        this.user = username;
    }

CodePudding user response:

You can add a member variable to your class:

string myUsername;

Then assign it in LateReturn:

public LateReturn(string username)
{
    InitializeComponent();
    this.myUsername = username;
}

Now in any method of your class you'll be able to access this.myUsername.

  • Related