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

帮忙翻译一句源代码,该怎么解决

2012-01-08 
帮忙翻译一句源代码C++中是:intWINAPISW_ReceiveCID(intnIndex,char*lpBuf)例子是如下调用的:BOOLWINAPIy

帮忙翻译一句源代码
C++中是:int   WINAPI   SW_ReceiveCID(int   nIndex,   char   *lpBuf);
例子是如下调用的:
BOOL   WINAPI   yzInitSystem()
{
char   buf[16];
int   i;

SW_Init();
SW_SetType(1);   //设置类型
                                LineCount=SW_GetCount();
strcpy(buf, "共 ");
itoa(LineCount,num,10);
strcat(buf,num);
strcat(buf, "线 ");
SetWindowText(GetDlgItem(hGWnd,IDC_LINE),buf);
                                for   (i=0;i <LineCount;i++)
                                {
                                                LineStatus[i]=0;     //线路状态
                                }
SetTimer(hGWnd,ID_TIME,20,TimerProc);  
return   TRUE;
}

在C#中应该如何写?
我如下写法
char[]   buf   =   new   char[50];
int   i;

                          int   LineCount=SW_GetCount();
                          for   (int   line   =   0;   line   <   LineCount;   line++)
                          {
                                  //收到CID处理
                                  i   =   SW_ReceiveCID(line,   buf);
                                  if   (i   ==   -1)
                                  {
                                          this.textBox1.Text   =   "4路电话语音盒是否安装! ";
                                          return;
                                  }
                                  else
                                          if   (i   !=   0)
                                          {
                                                  this.label2.Text   =   i.ToString();
                                                  this.textBox1.Text   =   "线 "   +   line.ToString()   +   ": ";


                                                  for   (int   n   =   0;   n   <   i;   ++n)
                                                  {
                                                          this.textBox1.Text   +=   buf[n].ToString().Trim();
                                                  }
                                          }
                          }
结果buf中全不是空,怎么回事?

[解决办法]
char[] buf = new char[50];只是创建了一个数组,并没给它置空,当然不会是空的。
数组是引用类型,当你char[] buf = new char[50];时,在内存给你划分了50个长度的char类型长度的空间。你此时有个指针指向这个空间,但这些空间里原本就有数据,你没有清空。

热点排行