Answer the question
In order to leave comments, you need to log in
How to parse String to Int in VS - via toolbox?
Hello everyone, such a question
. I have String Q1; Q2; Q3; Q4; Q5; Q6; Q7; - this is for example, the scores in each of them are Choice from 1 to 5.
I need to pass them to one Score variable which is Int (but if necessary, you can do it and String)
All this is done through the Visual Studio toolbox
At the moment it looks like this
Score = Convert.ToInt32(Q1) + Convert.ToInt32(Q2) + Convert.ToInt32(Q3) +
Convert.ToInt32(Q4) + Convert.ToInt32(Q5) + Convert.ToInt32(Q6) +
Convert.ToInt32(Q7)
Answer the question
In order to leave comments, you need to log in
Try this function
public int SumStrings(params string[] numbers)
{
return numbers.Sum(numberString => Convert.ToInt32(numberString));
}
Score = SumStrings(Q1, Q2, Q3, Q4, Q5, Q6, Q7);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question