There's with your idea see the following code using System;namespace ConsoleApplication1
{
public struct MyStruct
{
public int usercode;
public string[] username;
}; /// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{ /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
MyStruct mystruct;
mystruct.username = new string[10];
mystruct.username[1] = "cai" ;
mystruct.username[2] = "cai1" ;
mystruct.username[5] = "cai2" ;
mystruct.username[8] = "cai3" ;
mystruct.username[9] = "cai8" ; for (int i = 0 ;i< 10 ; i ++)
{
System.Console.Write (mystruct.username[i]) ;
}
System.Console.Read() ;
}
}
}
Is it what u want ?
{
public struct MyStruct
{
public int usercode;
public string[] username;
}; /// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{ /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
MyStruct mystruct;
mystruct.username = new string[10];
mystruct.username[1] = "cai" ;
mystruct.username[2] = "cai1" ;
mystruct.username[5] = "cai2" ;
mystruct.username[8] = "cai3" ;
mystruct.username[9] = "cai8" ; for (int i = 0 ;i< 10 ; i ++)
{
System.Console.Write (mystruct.username[i]) ;
}
System.Console.Read() ;
}
}
}
Is it what u want ?
public int usercode;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=10)]
public char[] username;
}
或者使用StringBuilder.