日期:2014-05-18  浏览次数:21340 次

C#如何在一个cs文件中用到另一个cs文件中的变量的值?
在1.cs中定义了这个变量所在的类,代码如下:
C# code

 public class FlowSize
    {
        public long up;
        public long down;
        public long flow;
        public long daysum;
        public long monthsum;
        public FlowSize()
        {
            this.down = 0;
            this.up = 0;
        }
        public void clear()
        {
            this.down = 0;
            this.up = 0;
        }
        public bool Isempty()
        {
            if ((this.down == 0) && (this.up == 0)) return true;
            else return false;
        }
        public static bool WriteDebugLog = true;
        public static int TimeWaitCloseMainWindow = 30;
        public static int TimeWaitClose = 30;
        public static int TimeWaitKillProcess = 30;
    }


在2.cs中实例化了这个类,实例名为grab和grab_flow,代码如下:
C# code

 public static void Refresh_TempData(FlowSize grab_flow)
        {
            DateTime time = DateTime.Now;
            string dbpath = Application.StartupPath + @"\FlowDB.mdb";
            OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + dbpath);
            long flow = 0;
            FlowSize grab, real;
            grab = new FlowSize();
            real = new FlowSize();
            try
            {
                con.Open();
                OleDbCommand cmd = con.CreateCommand();
                cmd.CommandText = "select * from FlowPerMonth where cstr(YearMonth) = '" + GetStandardYM(time)+ "'";
                
                OleDbDataReader reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    flow = Convert.ToInt64(reader["User_GB"].ToString()) * num + Convert.ToInt64(reader["User_B"].ToString());
                    
                }
                reader.Close();
                cmd.CommandText = "select * from FlowPerday where cstr(FlowData) ='" + GetStandardYMD(time) + "'";
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    grab.up += Convert.ToInt64(reader["Grab_up_GB"].ToString()) * num + Convert.ToInt64(reader["Grab_up_B"].ToString());
                  
                    grab.down += Convert.ToInt64(reader["Grab_down_GB"].ToString()) * num + Convert.ToInt64(reader["Grab_down_B"].ToString());
                    
                }
                reader.Close();
                con.Close();
                UpdateWindow.UpdateFlowMonth(flow+grab_flow.up+grab_flow.down);
               
                UpdateWindow.UpdateFlowPerDay(grab.up+grab_flow.up, grab.down+grab_flow.down);
            }
            catch (Exception ee)
            {
                Flowfairy.FairyLog.WriteLog(ee.ToString());
            }
        }


想在3.cs中带参访问某个php文件,参数是2.cs中grab.up+grab_flow.up+grab.down+grab_flow.down的结果,该怎样处理?

------解决方案--------------------
Import 2.cs所在的目录
调用处:
参数=c2.grab.up+c2.grab_flow.up+c2.grab.down+c2.grab_flow.down
------解决方案--------------------
你还没搞清许多基本概念啊?
Refresh_TempData(FlowSize grab_flow)
这个grab_flow明明是个参数来的

FlowSize grab, real;
这个grab只是个局部变量

我上面那样调用是不对的了。
------解决方案--------------------
本人才疏学浅,过来学习一下!
------解决方案--------------------
头晕目眩,不知道要搞什么
------解决方案--------------------
可以去看看

委托+事件