C#定义全局变量的方法

时间:2022-07-15 10:28:56

第一次做C/S的东西,遇见一个全局变量的问题.C/S中没有Session,Application这样的东西

上网查了知道原来是要设成一个静态变量类,现把代码列出来,以防遗忘

定义文件:

using System;
using System.Collections.Generic;
using System.Text;

namespace spider_demo
{
     public class BIANLIANG
     {
         private static string _url;
         private static string _webinclude;
         private static string _contentinclude;
         private static string _type;
         private static string _website;
         public BIANLIANG(string x1,string x2 ,string x3,string x4,string x5)
         {
             _url = x1;
             _webinclude = x2;
             _contentinclude = x3;
             _type = x4;

             _website = x5;
         }

         public static string url
         {
             get
             {
                 return _url;
             }
         }
         public static string webinclude
         {
             get
             {
                 return _webinclude;
             }
         }
         public static string contentinclude
         {
             get
             {
                 return _contentinclude;
             }
         }
         public static string type
         {
             get
             {
                 return _type;
             }
         }
         public static string website
         {
             get
             {
                 return _website;
             }
         }
     }  
}

写入变量:

     BIANLIANG xx = new BIANLIANG(url, webinclude, contentinclude,type,website);

 

读出变量:

string   aaaaaa=BIANLIANG.website.ToString();