visual studio - richTextBox make sum of all lines in c# -


is there way make sum of lines in richtextbox? lines in richtextbox numbers. want if richtextbox has 10 lines random numbers 10 lines must added each other. ex.:

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

then must happen is: 1+2+3+4+5+6+7+8+9+10 , answer appears in messagebox in case: 55

greetings michielvk

try this:

messagebox.show(string.format("sum of numbers {0}",     richtextbox1.text.split('\n').select(number => convert.toint32(number)).sum())); 

split text on new line character, convert string array numbers, sum , display in messagebox.

step step solution:

string[] stringarray = richtextbox1.text.split('\n');  int sum = 0; foreach (string element in stringarray) {     sum += convert.toint32(element); }  messagebox.show("sum of numbers " + sum); 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -