OMG, I was limited anything
博客园
::
首页
:: ::
联系
:: ::
管理
::
[笔记] C# 3.0 新特性[3]-Understanding Object Initializers
Code
using
System;
namespace
net30netfeature
{
public
class
ObjectInit
{
/**/
/*
* 对象初使化器包括了一个用逗号分隔的值列表。用{ and }包起来。被初使化的每个成员是公共的属性或字段。
* 在使用对象初始化器时,默认的构造函数被调用,然后在其后对相应的公共成员进行赋值。对象初始化器这个特性
* 实质上是在语法上进行了简化。生成的最终的IL还是一个调用默认的构造函数,然后在其后对相应的公共成员进行赋值
* 的过程
*/
public
static
void
Test()
{
Test1();
}
public
static
void
Test1()
{
//
Make a Point by setting each property manually.
Point firstPoint
=
new
Point();
firstPoint.X
=
10
;
firstPoint.Y
=
10
;
//
Make a Point via a custom constructor.
Point anotherPoint
=
new
Point(
20
,
20
);
//
Make some Point types using the new object init syntax.
//
Under C# 3.0, we could now make Points using any of the following approaches:
var yetAnotherPoint
=
new
Point
{ X
=
30
, Y
=
30
}
;
//
is implicitly typed
Point finalPoint
=
new
Point
{ X
=
30
, Y
=
30
}
;
//
隐示的调用默认的构造函数。
Point finalPoint1
=
new
Point()
{ X
=
30
, Y
=
30
}
;
//
显示的调用默认的构造函数。
/**/
/*
* 导致X value of 100 and a Y value of 100, regardless of the fact that our constructor arguments
* specified the values 10 and 16
*/
Point pt
=
new
Point(
10
,
16
)
{ X
=
100
, Y
=
100
}
;
Console.WriteLine(firstPoint.ToString());
Console.WriteLine(anotherPoint.ToString());
Console.WriteLine(yetAnotherPoint.ToString());
Console.WriteLine(finalPoint.ToString());
Console.WriteLine(finalPoint1.ToString());
Console.WriteLine(pt.ToString());
}
}
public
enum
PointColor
{ LightBlue, BloodRed, Gold }
public
struct
Point
{
public
int
xPos, yPos;
private
PointColor c;
public
Point(PointColor color)
{
xPos
=
0
; yPos
=
0
;
c
=
color;
}
public
Point(
int
x,
int
y)
{
xPos
=
x; yPos
=
y;
c
=
PointColor.Gold;
}
public
int
X
{
get
{
return
xPos; }
set
{ xPos
=
value; }
}
public
int
Y
{
get
{
return
yPos; }
set
{ yPos
=
value; }
}
//
public override string ToString()
//
{ return string.Format("[{0}, {1}]", xPos, yPos); }
public
override
string
ToString()
{
return
string
.Format(
"
[{0}, {1}, Color = {2}]
"
, xPos, yPos, c); }
}
public
class
TestFalgEnum
{
public
static
void
TestEnumFlag()
{
//
1248
//
int i = 1;
//
int ii = 1;
//
Console.WriteLine(i ^ ii);
test aa
=
new
test();
test bb
=
new
test();
aa
=
test.a;
bb
=
test.b;
test cc
=
aa
|
bb;
Console.WriteLine(Enum.Format(
typeof
(test), cc,
"
d
"
));
Console.WriteLine(cc
==
test.c);
}
}
[Flags]
enum
test
{
a
=
1
, b
=
2
, c
=
3
, d
=
8
}
}
posted on 2008-02-20 14:22
共同学习,共同进步
阅读(47)
评论(1)
编辑
收藏
网摘
评论
#1楼
2008-04-04 12:50
dxd [未注册用户]
帮我一把,好吗?
我在创建生成定义时,启动的项目生成类型的向导,但我什么也干不了。只有一个Cancel按钮可以使用,连个文本输入框都没有。
在msdn上看了如何:创建新的生成类型(
http://msdn2.microsoft.com/zh-cn/library/ms181716
(VS.80).aspx)。
问题是我的“生成”菜单上没有“新建团队项目生成类型”这一项,能说说怎么回事吗。
ps:刚刚自己学习安装完TFS2008中文工作组版。
环境:
server:windows2008、iis7、sql2005、tfs2008 chs workgroup、team build。
client:windows vista、team explorer、vsts2008
学习msdn上的帮助文章整整一周了,也没找到解决办法.
回复
引用
新用户注册
刷新评论列表
标题
姓名
主页
Email
(博主才能看到)
验证码
*
看不清,换一张
[
登录
][
注册
]
内容(请不要发表任何与政治相关的内容)
网站首页
新闻频道
社区
小组
博问
网摘
闪存
找找看
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
"五向定位"职业成长路线公开课(上海、南京、大连)
Google站内搜索
相关文章:
温故知新ASP.NET 2.0(C#)系列
什么是C#及.NET FrameWork
使用Visual Studio2005入门.Net2.0系列视频教程
prototype.js 1.4版开发者手册(强烈推荐)
和 C#4.0 团队面对面
Flash Player 10 的新特性
求 C#3.0 PPT 课件
关于C#3.0中新关键字var
《C# 3.0 Unleashed》征集译者
C#和.NET 2.0实战-平台、语言与框架
相关链接:
最新IT新闻:
OpenOffice.org 3.0.0发布
Linux终于迎来了“同等”的Flash播放器
百度和讯全财经网正式上线
微软将于明天召开Blue Hat安全大会
超强的支付宝Flash招聘广告
与我联系
发短消息
搜索
留言簿
(7)
给我留言
查看留言
我参加的小组
LumaQQ.NET
.NET 3.x
SharePoint
你必须知道的.NET
Web技术联盟
WCF技术研究
Microsoft New Skill
框架设计
易书阁
我参与的团队
SharePoint团队(0/747)
O/R Mapping团队(0/209)
Windows Vista开发(0/240)
随笔分类
(1)
AxAppModule
(rss)
AxTechModule
(rss)
收藏(1)
(rss)
Powered by:
博客园
Copyright © 共同学习,共同进步