Add numbers in c#

后端 未结 7 992
难免孤独
难免孤独 2020-12-21 12:19

i have a numerical textbox which I need to add it\'s value to another number I have tried this code

String add = (mytextbox.Text + 2)

but

7条回答
  •  有刺的猬
    2020-12-21 13:05

    const int addend = 2; 
    string myTextBoxText = mytextbox.Text;
    var doubleArray = new double[myTextBoxText.ToCharArray().Length];
    for (int index = 0; index < myTextBoxText.ToCharArray().Length; index++)
    {
        doubleArray[index] = 
            Char.GetNumericValue(myTextBoxText.ToCharArray()[index]) 
            * (Math.Pow(10, (myTextBoxText.ToCharArray().Length - 1) - index));
    }
    string add  = 
        (doubleArray.Aggregate((term1, term2) => term1 + term2) + addend).ToString();
    

提交回复
热议问题