این برنامه ای هست که میاد دو عدد رو در تکسهای مختلف با هم جا به جا میکنه
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 Change
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int x = Convert.ToInt32(textBox1.Text);
int y = Convert.ToInt32(textBox2.Text);
int temp = x;
x = y;
y = temp;
textBox1.Text = x.ToString();
textBox2.Text = y.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
Random r = new Random();
textBox1.Text = r.Next(100).ToString();
}
}
}
حالا برنامه پایین با کلاس بندی نوشته شده
کلاس:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Change_Class
{
public class ClassCahnge
{
public int x;
public int y;
public ClassCahnge(int a,int b)
{
x = a;
y = b;
}
public ClassCahnge()
{
// TODO: Complete member initialization
}
public void Change()
{
int temp = x;
x = y;
y = temp;
}
public void rand(out int Z)
{
Random ra = new Random();
Z = ra.Next(100);
}
}
}
فراخونی:
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 Change_Class
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
علاقه مندی ها (Bookmarks)