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

关于字符串参数传递有关问题

2011-12-28 
关于字符串参数传递问题有一C++类TB001:它里面有一方法:intInsertRecord1(intid,char*str1,char*str2)C#

关于字符串参数传递问题
有一C++类TB001:
它里面有一方法:
int   InsertRecord1(int   id,   char*   str1,   char*   str2);


C#函数要调用它!代码如下:

TB001   tb   =   new   TB001();
int   id   =   1;
string   str1   =   "TMD ";
byte[]   buf   =   System.Text.Encoding.ASCII.GetBytes(str1);
sbyte[]   sbuf   =   new   SByte[buf.Length];

for   (int   i   =   0;   i   <   buf.Length;   i++)
{
        sbuf[i]   =   (sbyte)buf[i];
}
tb.InsertRecord1(id,   ref   sbuf[0],   ref   sbuf[0]);     //结果这一行这里失败:

Error         1         The   best   overloaded   method   match   for   'Test.TB001.InsertRecord1(int,   sbyte*,   sbyte*) '   has   some   invalid   arguments         D:\ExtremeDB\Test2\TestApp\Program.cs         115         13         TestApp

Error         2         Argument   '2 ':   cannot   convert   from   'ref   sbyte '   to   'sbyte* '         D:\ExtremeDB\Test2\TestApp\Program.cs         115         38         TestApp

请问我应该怎么写?

[解决办法]
帮顶一下.. 看到沙发... 不顶对不起自己

虽然不会..
[解决办法]
用StringBuilder
[解决办法]
用StringBuilder代替你的数组,这都不会?
[解决办法]
byte[] buf = System.Text.Encoding.ASCII.GetBytes(str1);
sbyte[] sbuf = new SByte[buf.Length];
改为:
StringBuilder buf=new StringBuilder(system.Text.Encoding.ASCII.GetBytes(str1);
StringBuilder sbuf=new StringBuilder(buf.Length.toString());

for (int i = 0; i < buf.Length; i++)
{
sbuf[i] = (sbyte)buf[i];
}
改为:
for(int i=0;i <buf.length;i++)
{
sbuf.append(buf[i]);
}
//记不太清楚了,自己试一下就知道了,

热点排行