Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to accept values into array using Textbox and display the Sum of numbers using a Button?
Posted

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication8
{
public partial class Form2 : Form
{
int[] n1 = new int[3];

public Form2()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
//n1[0] = Int32.Parse(textBox1.Text);
//n1[1] = Int32.Parse(textBox2.Text);
//n1[2] = Int32.Parse(textBox3.Text);
//textBox4.Text = n1.Sum().ToString();

int value;

if (int.TryParse(textBox1.Text, out value))
n1[0] = value;
if (int.TryParse(textBox2.Text, out value))
n1[1] = value;
if (int.TryParse(textBox3.Text, out value))
n1[2] = value;
textBox4.Text = n1.Sum().ToString();


}
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900