首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C# 调用有关问题

2013-01-23 
C# 调用问题Mainform.cs中public static string isstr void spPort_DataReceived(object sender, Sys

C# 调用问题
Mainform.cs中 
 public static string isstr = "";
  void spPort_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            int DataLength = spPort.BytesToRead;
            int i = 0;
            StringBuilder sb = new StringBuilder();
            while (i < DataLength)
            {
                byte[] ds = new byte[1024];
                int len = spPort.Read(ds, 0, 1024);
                sb.Append(Encoding.ASCII.GetString(ds, 0, len));
                i += len;
            }
           
            isstr = sb.ToString();
          }
protocol.cs中
    internal void SetUserTime(string str_time)
        {
            str_time = MainFrom.isstr;   //我想调过isstr中的数据,但是不行,显示里面是空的       
            if (str_time.Length != 26)
            {
                return;
            }        
            else
            {
            UserV = str_time.Substring(str_time.Length - 7, 2).ToString() + "."
               + str_time.Substring(str_time.Length - 5, 2).ToString();
            }


        }
大家给看看,怎么把isstr中的数据调过来 c#
[解决办法]
断点一下 , 看程序运行的先后顺序 
[解决办法]
创建对象是最简单的办法
可以把Mainform  当参数
Mainform mf;
public protocol(Mainform mf)
{
    this.mf = mf;
}
public void SetUserTime()
{
 if (mf.str_time.Length != 26)
}
另外最好不要用static
[解决办法]
定义的变量是静态的!不能创建对象的,应该是类名.静态变量名


[解决办法]
C# 调用有关问题

热点排行