结构数组传递 [英] structure array passing
本文介绍了结构数组传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i在c#windows窗体中创建了一个结构数组,我希望将这个structarray转移到另一个form.h我可以这样做吗?请帮助...
i created a structure array in c#windows form and i want to transfer this structarray to another form.how can i do this??pls help...
推荐答案
创建一个新项目,称之为DataStructures。然后在DataStructures命名空间中声明以下两个类。
Create a new project, calling it, say, DataStructures. Then declare, within the DataStructures namespace, the following two classes.
// TestStruct.cs
namespace DataStructures
{
// ********************************************** class TestStruct
public class TestStruct
{
public struct Test_Struct
{
public string name;
public int code;
};
} // class TestStruct
} // namespace DataStructures
和
and
// TestArray.cs
namespace DataStructures
{
// *********************************************** class TestArray
public class TestArray
{
public static TestStruct.Test_Struct [ ] test_structs =
new TestStruct.Test_Struct [ 200 ];
} // class TestArray
} // namespace DataStructures
现在有两种形式,请使用DataStructures,如下所示。请注意,该示例是Form1; Form2代码是相同的。
Now in the two forms, use DataStructures as follows. Note that the example is Form1; Form2 code is the same.
// Form1.cs
using System.Windows.Forms;
namespace ArrayOfStructs
{
// *************************************************** class Form1
public partial class Form1 : Form
{
// ***************************************************** Form1
public Form1 ( )
{
InitializeComponent ( );
for ( int i = 0;
( i < DataStructures.TestArray.test_structs.Length );
i++ )
{
}
}
} // class Form1
} // namespace ArrayOfStructs
希望有所帮助。
Hope that helps.
有几种方法。例如,您可以将其设为第一种形式的公共属性。
There are several ways. For instance you could make it a public property of the first form.
这篇关于结构数组传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文