如何使用Textbox将值接受到数组中并使用Button显示数字的总和? [英] How to accept values into array using Textbox and display the Sum of numbers using a Button?

查看:70
本文介绍了如何使用Textbox将值接受到数组中并使用Button显示数字的总和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用文本框接受数组到数组并使用按钮显示数字总和?

推荐答案

嗨!!!查看此链接

http ://social.msdn.microsoft.com/Forums/en-AU/csharpgeneral/thread/edf0ce05-21ec-49fa-bd64-72e30be7148c [ ^ ]
Hi!!! Check this link
http://social.msdn.microsoft.com/Forums/en-AU/csharpgeneral/thread/edf0ce05-21ec-49fa-bd64-72e30be7148c[^]


使用System;

使用System.Collections.Generic;

使用System.ComponentModel;

使用System.Data;

使用System.Drawing;

使用System.Linq;

使用System.Text;

使用System.Windows.Forms; < br $>


命名空间WindowsFormsApplication8

{

公共部分类Form2:表格

{

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();





}

}

}
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();


}
}
}


这篇关于如何使用Textbox将值接受到数组中并使用Button显示数字的总和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆