在什么地方写,怎么写,我要详细的代码!谢谢啦

解决方案 »

  1.   

    写一个类,
     Public Static SharedProperties
    {
    public static int SharedNumber;
    }然后你的所遇form就可以访问到这个静态类里的SharedNumber了。
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.Text;namespace WindowsApplication1
    {
        
        class Class1
        {
            public static string str = "aaa";    }
    }
      

  3.   

    任何地方都可
    public static object m_Object=null;
    public static int  m_Int=0;
      

  4.   

    你可以在单独的模块里写,也可以直接写在你form所在的项目里。
      

  5.   

    1.定义成静态的
    2.定义在Program里面
    3.放在资源文件里也可以
    ……
      

  6.   

    首先C#是不提倡把变量写成全局变量,如果说必须要有个全局变量,可以写一个共享类,还有一种如果是简单类型变量可以把它定义在一个xml文件里,
      

  7.   

    静态成员就可以,用STATIC关键字来声明就OK了,
    PUBLIC STATIC 类型 变量名 = 初始值;
      

  8.   

    还是不知道怎么写,这是我的代码,里面的Temp_ID是我要在别的FORM中也能用到的变量,我要怎么定义,然后在另一个表单中直接用,还是要写什么代码?
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using DevExpress.Web.ASPxGridView;
    using System.Drawing;
    using System.IO;
    using System.Web.Configuration;
    using System.Drawing.Imaging;
    using DevExpress.Web.ASPxUploadControl;
    public partial class exam_question_ope : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
          
        }
     
        protected void ASPxGridView1_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            int index = Convert.ToInt32(e.Parameters);      
           string Temp_ID = ASPxGridView1.GetRowValues(index, new String[] { "Choose_ID" }).ToString();
           // Session["IssueIDInSession"] = ASPxGridView1.GetRowValues(index, new String[] { "Choose_ID" }).ToString();
           
        }
       }
      

  9.   

    新建一个类,变量定义成静态的,如
    using System;
    using System.Collections.Generic;
    using System.Text;namespace Program
    {
        class UserHelper
        {
            public static int loginId;
        }
    }以后就可以用UserHelper.loginId可以访问到了
      

  10.   

    public static 你需要的数据类型 数据名
    写在声明变量的地方
    例:
    声明:
    ……
    namespace SetStatic
    {
        class class1
        {
            public static int ics = 0;
            ……
         }
    }
    访问:
    在你需要的地方:class1.ics = Convert.toInt32(textbox1.text);//设置
                  lable1.text = class1.ics.toString();//访问
      

  11.   

    1.如果有必要可以写个父类定义在里面,所有form都继承它。
    2.在Program.cs定义一个类的全局静态变量public static string xxxx,调用的时候直接Program.xxxx就可以了
      

  12.   

    public partial class exam_question_ope : System.Web.UI.Page 

    public   static string Temp_ID 
        protected void Page_Load(object sender, EventArgs e) 
        { 
          
        }     protected void ASPxGridView1_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) 
        { 
            int index = Convert.ToInt32(e.Parameters);       
           Temp_ID = ASPxGridView1.GetRowValues(index, new String[] { "Choose_ID" }).ToString(); 
          // Session["IssueIDInSession"] = ASPxGridView1.GetRowValues(index, new String[] { "Choose_ID" }).ToString(); 
          
        } 
      

  13.   

    调的时候直接 exam_question_ope.Temp_ID
      

  14.   

    。。看你的代码是web程序。想全局可访问把值放application或者session里就ok了。
      

  15.   

    建议lz写为属性,参考代码:
    private string _temp_ID = string.Empty;
    internal string Temp_ID
    {
        get
        {
            return this._temp_ID;
        }
        set
        {
            if (!string.Equals(this._temp_ID, value))
            {
                this._temp_ID = value;
                this.OnTempIDChanged();
            }
        }
    }//当Temp_ID属性改变时的相关处理
    private void OnTempIDChanged()
    {
        //Do sth...
    }
      

  16.   

    我在别的表单中用string zx = "update [Exam_ChooseQues] set [content] ='" + Address1 + "'where [Choose_ID]=exam_question_ope.Temp_ID";,提示错误说列前缀exam_question_ope有问题,怎么回事?
      

  17.   

    C#是不提倡把变量写成全局变量,如果说必须要有个全局变量,可以写一个共享类,在里面定义一个public static XXX
    如果是同一个程序集 就直接掉这个 类名称.XXX 否则需要引用类所在程序集
      

  18.   

    我用的是15楼的代码,经过断点测试Temp_ID的值能得到,可是在别的表单中用exam_question_ope.Temp_ID,就提示错误,不知道为什么,这么用不对吗?
    public partial class exam_question_ope : System.Web.UI.Page 

    public  static string Temp_ID 
        protected void Page_Load(object sender, EventArgs e) 
        { 
          
        }     protected void ASPxGridView1_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) 
        { 
            int index = Convert.ToInt32(e.Parameters);       
          Temp_ID = ASPxGridView1.GetRowValues(index, new String[] { "Choose_ID" }).ToString(); 
          // Session["IssueIDInSession"] = ASPxGridView1.GetRowValues(index, new String[] { "Choose_ID" }).ToString(); 
          
        } 
      

  19.   

    提示的错误是:列前缀 'exam_question_ope' 与查询中所用的表名或别名不匹配。 string zx = "update [Exam_ChooseQues] set [content] ='" + Address1 + "'where [Choose_ID]=exam_question_ope.Temp_ID";
      

  20.   

    string zx = "update [Exam_ChooseQues] set [content] ='" + Address1 + "'where [Choose_ID]=" + exam_question_ope.Temp_ID.ToString();