这样试试:[ 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数组的值.
}

解决方案 »

  1.   

    给你个相关的例子!
    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
      

  2.   

    呵呵,
    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数组的值.
    }
      

  3.   

    {'a', 'b', 'c'}好像.net中不能这么写
      

  4.   

    你这样做也是可以的:
    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();
    }
      

  5.   

    为什么我写的char charVal = 'a';就提示错误,文本中的字符太多,
    我从msdn里考的旧没问题,难道我写的''不对吗,
      

  6.   

    你可以这样来取char数组的字符串表示形式:string s = new string(Sql.tables);
    Console.WriteLine(s);
      

  7.   

    char charVal = 'a';
    这个起码没有错,你好好看一下你输入的字符是不是半角的.
      

  8.   

    感谢 hbxtlhx(下着春雨的天),是可以的,但我写'a'就出错,呵呵,考来就没事