c# 扫描一个变量

来源:百度知道 编辑:UC知道 时间:2024/09/20 02:47:38
c#
请问高手:有一个变量i,有初值(如:i=5;),标志位flag=0,现在我要每一秒扫描一次他的值,如果发生变化,置标志位flag=1,把其值赋给另一变量j,并要把扫描到的值作为初值,继续扫描。最好能有详细程序说明。

小弟只有10分了,全部奉上。
To:aideqiuqian7
你实现了我说的一部分功能,先谢谢了。
但是我还要把新扫描到的值作为初值继续扫描。比如:i=5;扫描一次后发现i=6;然后置flag=1,把6赋给j,再置flag=0;
重要的是:我要以6作为初值,继续扫描,一旦发现i不等于6了,重新置flag,和赋j值.

加个Timer控件
在他的事件里写代码

给你所有的代码,你再看看。。。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;

using System.Data.OleDb;
using System.Reflection;

namespace WindowsApplication1
{

public partial class Form1 : Form
{

int i;
int flag = 0;
public Form1()
{
InitializeComponent();
}

private void Form1_Click(object sender, EventArgs e)
{
}

private void button2_Click(object sender, EventArgs e)
{
i = 5;
}