using System;
namespace ConsoleApplication4
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public struct Point
{
public int x, y; public Point(int p1, int p2)
{
x = p1;
y = p2;
}
}
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Point p=new Point(1,2);
Console.WriteLine("Point.X={0},Point.Y={1}",p.x,p.y);
//使用 New 运算符创建结构对象时,将创建该结构对象,
//并且调用适当的构造函数。与类不同的是,
//结构的实例化可以不使用 New 运算符。
//如果不使用“新建”(new),那么在初始化所有字段之前,
//字段将保持未赋值状态,且对象不可用。
//Point t;
//t.x=1; //没有出始化结构体Point字段y,根本无法编译通过.
//Console.WriteLine("Point.X={0},Point.Y={1}",t.x,t.y);
Console.ReadLine();
}
}
}
namespace ConsoleApplication4
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public struct Point
{
public int x, y; public Point(int p1, int p2)
{
x = p1;
y = p2;
}
}
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Point p=new Point(1,2);
Console.WriteLine("Point.X={0},Point.Y={1}",p.x,p.y);
//使用 New 运算符创建结构对象时,将创建该结构对象,
//并且调用适当的构造函数。与类不同的是,
//结构的实例化可以不使用 New 运算符。
//如果不使用“新建”(new),那么在初始化所有字段之前,
//字段将保持未赋值状态,且对象不可用。
//Point t;
//t.x=1; //没有出始化结构体Point字段y,根本无法编译通过.
//Console.WriteLine("Point.X={0},Point.Y={1}",t.x,t.y);
Console.ReadLine();
}
}
}
解决方案 »
- 帮忙分析个模拟POST,版主,求助啊
- 麻烦大家绑我把这段画excel 饼图的代码翻译成 c# 谢谢大家了!
- 请问调用Winapi的UpdateData函数应该引用哪个动态链接库啊?在线等!谢谢!
- C# combobox的SelectedValueChanged事件问题???在线急等!!!!
- 一个关于socket的简单问题
- 如何理解线程、消息循环、应用程序、窗口的关系???
- 急:请教如何往oracle数据库中的时间类型字段传空值!
- foreach( Control z in Controls )会遍例所有form控件,怎样才能遍例特定的控件?
- 在textbox中如何定位光标在指定位置?
- 怎样做成在浏览器打开Excel啊
- api函数求助~~~~~~
- 如何用c#开发GIS?是否还要配置运行环境和用到那些类?
//伪代码 意会
struct data{
string name
string pwd
}class proc{
public data getData(string select){
//todo
}
}static void main(){
proc p = new p;
data d = p.getData("获得数据的条件");
}
可是如果 p.getData() 没有得到满足条件的数据 而无法封装成data类型的 对象那么data d = p.getData() 中的d 应该是个无效的对象(如果是引用对象就应该是NULL)
可是d在这里是个struct 而且微软一再声明它数据值类型 那我要怎么判断 这个对象是否有效呢?
if(d == null){
//d没有实例化
}
这样是会报错的