jame anasere yek araye anjam mide:
کد:
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 AddHomeAray
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int i = 0;
const int s = 2;
int[] Number = new int[s];
private void txt_EnterInteger_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
{
Number[i] = Convert.ToInt32(txt_EnterInteger.Text);
i++;
if (i < s)
txt_EnterInteger.Text = "";
else
{
MessageBox.Show("Enough...");
i = 0;
}
}
}
public int addAray(int[] a)
{
int c = 0;
for (int j = 0; j < s; j++)
c += a[j];
return c;
}
private void btn_ClickResult_Click(object sender, EventArgs e)
{
int Capacity;
Capacity = addAray(Number);
lbl_ShowResult.Text = Capacity.ToString();
}
}
}
کلاس:
کد:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AddHomeArray_Class
{
public class AddHome
{
public const int a = 3;
public int[] number = new int[a];
public AddHome(int[] NUMBER)
{
number = NUMBER;
}
public int AddArrayHome()
{
int c = 0;
for (int j = 0; j < a; j++)
c += number[j];
return c;
}
}
}
فراخونی:
کد:
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 AddHomeArray_Class
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public AddHome AddHome;
int i = 0;
const int s = 3;
int[] Number = new int[s];
private void txt_EnterInteger_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
{
Number[i] = Convert.ToInt32(txt_EnterInteger.Text);
i++;
if (i < s)
txt_EnterInteger.Text = "";
else
{
MessageBox.Show("Enough...");
i = 0;
}
}
}
private void btn_ClickResult_Click(object sender, EventArgs e)
{
int Capacity;
AddHome AD = new AddHome(Number);
Capacity = AD.AddArrayHome();
lbl_ShowResult.Text = Capacity.ToString();
}
}
}
علاقه مندی ها (Bookmarks)