namespace myTestTB
{
public struct ss
{
public string m_sType;
public string m_sName;
public int m_iLength;
public short m_shPresize;
public bool m_bNullable;
public bool m_bAutoInc;
public int m_iIncSeed;
public int m_iIncStep;
}
public class myTestTB_edit : System.Web.UI.Page
{
ss [] sDT = new ss("","",3,2,true,false,2,8,9); ....
}
c:\inetpub\wwwroot\WebApplication5\myTestTB_edit.aspx.cs(30): The type 'myTestTB.ss' has no constructors defined
c:\inetpub\wwwroot\WebApplication5\myTestTB_edit.aspx.cs(101): 'myTestTB.ss' denotes a 'class' where a 'variable' was expected怎么错了,到底如何在.NET里使用结构体?
{
public struct ss
{
public string m_sType;
public string m_sName;
public int m_iLength;
public short m_shPresize;
public bool m_bNullable;
public bool m_bAutoInc;
public int m_iIncSeed;
public int m_iIncStep;
}
public class myTestTB_edit : System.Web.UI.Page
{
ss [] sDT = new ss("","",3,2,true,false,2,8,9); ....
}
c:\inetpub\wwwroot\WebApplication5\myTestTB_edit.aspx.cs(30): The type 'myTestTB.ss' has no constructors defined
c:\inetpub\wwwroot\WebApplication5\myTestTB_edit.aspx.cs(101): 'myTestTB.ss' denotes a 'class' where a 'variable' was expected怎么错了,到底如何在.NET里使用结构体?
解决方案 »
- Linq中的OrderBy哪错了?
- 问个wf持久化问题,急。。。
- 帮我写个c#版的http代理程序
- "DataReceive"的重载均与委托“......”不匹配
- 如何关闭已打开的子窗体?
- 数组已经 new出来了 没有定大小 还可以不可以 向里面添元素 如果可以 怎么作
- 200分问IT?谁主沉浮!不是我年少轻狂,而是我在网海里浮沉了一个星期,也没有找到船!DataGrid嵌套DataGrid???
- 关于API WriteFile()老是发送失败的问题?研究三天了,未果,求帮助!大散分!!!!
- 关于NPIO向word导入图片 开启流的问题
- 关于查看API User32.dll 方法的问题
- 关于SqlDataAdapter的问题
- 如何在PictureBox里实现滚动条?
结构不能有以下形式的初始值设定项:base (argument-list)。
C# 关键字 | 结构教程 | 默认值表 | 内置类型表 | 类型 | 值类型 | class | interface
struct 类型是一种可包含构造函数、常数、字段、方法、属性、索引器、运算符、事件和嵌套类型的值类型。struct 类型的声明格式如下:[attributes] [modifiers] struct identifier [:interfaces] body [;]
其中: attributes(可选)
附加的声明性信息。有关属性和属性类的更多信息,请参见 17. 属性。
modifiers(可选)
允许使用的修饰符有 new 和四个访问修饰符。
identifier
struct 名称。
interfaces(可选)
包含结构所实现的接口的列表,接口间由逗号分隔。
body
包含成员声明的结构体。
备注
struct 类型适合表示如点、矩形和颜色这样的轻量对象。尽管可能将一个点表示为类,但结构在某些方案中更有效。例如,如果声明一个含有 1000 个点对象的数组,则将为引用每个对象分配附加的内存。在此情况下,结构的成本较低。声明结构的默认(无参数)构造函数是错误的。总是提供默认构造函数以将结构成员初始化为它们的默认值。在结构中初始化实例字段是错误的。使用 new 运算符创建结构对象时,将创建该结构对象,并且调用适当的构造函数。与类不同的是,结构的实例化可以不使用 new 运算符。如果不使用 new,那么在初始化所有字段之前,字段将保持未赋值状态且对象不可用。对于结构,不像类那样存在继承。一个结构不能从另一个结构或类继承,而且不能作为一个类的基。但是,结构从基类 Object 继承。结构可实现接口,其方式同类完全一样。与 C++ 不同,无法使用 struct 关键字声明类。在 C# 中,类与结构在语义上是不同的。struct(结构)是值类型,而 class(类)是引用类型。有关值类型功能的更多信息,请参见值类型。除非需要引用类型语义,否则,小于 16 字节的类被系统作为结构处理可能更高效。
比如 ss()正确
而ss("","",3,2,true,false,2,8,9);就需要有ss(string,string,....)之类的构造函数了
{
string m_sType;
string m_sName;
int m_iLength;
short m_shPresize;
bool m_bNullable;
bool m_bAutoInc;
int m_iIncSeed;
int m_iIncStep;
public void ss(string s1,string s2,int i1,short shI1,bool b1,bool b2,int i2,int i3)
{
m_sType = s1;
m_sName = s2;
m_iLength = i1;
m_shPresize = shI1;
m_bNullable = b1;
m_bAutoInc = b2;
m_iIncSeed = i2;
m_iIncStep = i3;
}
}
+了一个构造函数还是有错误:
c:\inetpub\wwwroot\WebApplication5\myTestTB_edit.aspx.cs(26): 'ss': member names cannot be the same as their enclosing type