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 Calculate
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_Click_Click(object sender, EventArgs e)
{
int r, Cal = 0;
int n = Convert.ToInt32(txt_Integer.Text);
while(n!=0)
{
r = n % 10;
n = n / 10;
Cal = Cal + r;
}
//MessageBox.Show(Cal.ToString());
lbl_Show.Text = Cal.ToString();
txt_Integer.Text = "";
}
}
}
این همین برنامه بالاست منتها با کلاس بندی:
کلاس:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Calculate_Class
{
public class RectAngle
{
public int tool;
public int arz;
public RectAngle(int Tool, int Arz)
{
arz = Arz;
tool = Tool;
}
public int Masahat()
{
int s = tool * arz;
return s;
}
public int Mohit()
{
int m = (tool + arz) * 2;
return m;
}
}
}
فراخونی:
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 Calculate_Class
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public RectAngle RectAngle;
private void button1_Click(object sender, EventArgs e)
{
RectAngle = new RectAngle(Convert.ToInt32(textBox1.Text),Convert.ToInt32(textBox2.Text));
int c = RectAngle.Masahat();
int z = RectAngle.Mohit();
MessageBox.Show(" Masahat: "+c.ToString() +" "+" Mohit: "+z.ToString());
علاقه مندی ها (Bookmarks)