这样试试:[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Ansi )]
public struct SE_SQL_CONSTRUCT
{
[MarshalAs(UnmanagedType.U4)]
public int num_tables ;
[MarshalAs(UnmanagedType.ByValArray ,SizeConst=128)]
public char[] tables;
[MarshalAs(UnmanagedType.LPWStr)]
public string where;
};public void abc(ref Message msg)
{ SE_SQL_CONSTRUCT Sql =new SE_SQL_CONSTRUCT();
Sql.num_tables = 1;
Sql.where ="DELETED_AT = 20";
Sql.tables = new char[]{'a', 'b', 'c'};//对char数组的值.
}
public struct SE_SQL_CONSTRUCT
{
[MarshalAs(UnmanagedType.U4)]
public int num_tables ;
[MarshalAs(UnmanagedType.ByValArray ,SizeConst=128)]
public char[] tables;
[MarshalAs(UnmanagedType.LPWStr)]
public string where;
};public void abc(ref Message msg)
{ SE_SQL_CONSTRUCT Sql =new SE_SQL_CONSTRUCT();
Sql.num_tables = 1;
Sql.where ="DELETED_AT = 20";
Sql.tables = new char[]{'a', 'b', 'c'};//对char数组的值.
}
000: // Structs\struct1.cs
001: using System;
002: struct SimpleStruct
003: {
004: private int xval;
005: public int X
006: {
007: get {
008: return xval;
009: }
010: set {
011: if (value < 100)
012: xval = value;
013: }
014: }
015: public void DisplayX()
016: {
017: Console.WriteLine("The stored value is: {0}", xval);
018: }
019: }
020:
021: class TestClass
022: {
023: public static void Main()
024: {
025: SimpleStruct ss = new SimpleStruct();
026: ss.X = 5;
027: ss.DisplayX();
028: }
029: }这个例子的输出是:The stored value is: 5
public void abc(ref Message msg)
去掉里面的参数:
public void abc()
{ SE_SQL_CONSTRUCT Sql =new SE_SQL_CONSTRUCT();
Sql.num_tables = 1;
Sql.where ="DELETED_AT = 20";
Sql.tables = new char[]{'a', 'b', 'c'};//对char数组的值.
}
public void abc()
{ SE_SQL_CONSTRUCT Sql =new SE_SQL_CONSTRUCT();
Sql.num_tables = 1;
Sql.where ="DELETED_AT = 20";//可以赋值 但tables怎么赋值?
//Sql.tables = new char[]{'a', 'b', 'c'};
Sql.tables = "abcdefg".ToCharArray();
}
我从msdn里考的旧没问题,难道我写的''不对吗,
Console.WriteLine(s);
这个起码没有错,你好好看一下你输入的字符是不是半角的.