How to increment a string variable c # [duplicate]

0

I have been developing a new application in fact I need to increment the variable

public string malcoins = "0";

Good to start, I will not be able to get the whole code because it is very large and here I only accept a certain number of characters I tried before without success. good here in this part of the code that I need to increment the variable and then refresh the variable that supposedly is a type of punctuation given to the user or removed here the varialvel and put in a label

label2.Text = malcoins;

and here when the user clicks on the mailbox

private void button1_Click(object sender, EventArgs e)
    {
        Clipboard.SetText(messageTextBox.SelectedText);
        Process.Start(Clipboard.GetText());

        malcoins = Convert.ToInt32(malcoins) + 100;
        deletemenssage();

    }

I tried this way with the code assima but without success to eliminate the error. Error 1 Can not implicitly convert type 'int' to 'string'
TestForm.cs 961 24

    
asked by anonymous 21.07.2017 / 21:00

1 answer

2

Option 1

Do the right thing and change the type of variable malcoins

public int malcoins = 0;

In the click event

private void button1_Click(object sender, EventArgs e)
{
    Clipboard.SetText(messageTextBox.SelectedText);
    Process.Start(Clipboard.GetText());

    malcoins = malcoins + 100;
    deletemenssage();
}

And change at time to show in label

label2.Text = malcoins.ToString();

Option 2

Convert the calculation result to string to put in the variable malcoins

private void button1_Click(object sender, EventArgs e)
{
    Clipboard.SetText(messageTextBox.SelectedText);
    Process.Start(Clipboard.GetText());

    malcoins = (Convert.ToInt32(malcoins) + 100).ToString();
    deletemenssage();
}
    
21.07.2017 / 21:13