Beginner with c# 6
来源:互联网 发布:喜马拉雅录音软件下载 编辑:程序博客网 时间:2024/06/11 06:18
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
1。6 统一系统类型(Type system unification)
c#独创了一种类型——统一系统类型(为了这个累刑,我头疼死了。谁有更好的名字,请务必告诉
我)。总之,所有的其他类型,包括值和引用,都可以被当作统一系统类型来对待。从概念上说,
所有的类型都从它派生。这样,其他的类型就可以使用统一系统类型的属性和方法。包括一些“简
单”类型,如:int。还是给个例子吧:*/
using System;
class Test
{
static void Main() {
Console.WriteLine(3.ToString());
}
}
/*“3.ToString()”调用了object的“ToString()”方法。相信学过c/c++的朋友都知道要输出一个
数字有多麻烦,现在就省事了。再看一个:*/
class Test
{
static void Main() {
int i = 123;
object o = i; // boxing
int j = (int) o; // unboxing
}
}
/* 这个像帽子戏法的例子中,从“int”转换成“object”,又转换回来。这样一来,在值和引用
之间就架起了一座桥梁。这样有什么用呢。即兴举一个常见的例子...就min把。在c/c++中:*/
// c/c++ code
void min(int i, int j)
{
return ((i < j) ? i : j);
}
/* 如果比较的不是int,或者说可能是int,也可能是float、double呢?可以这样:*/
template<class T>
T min (T i, T j)
{
return ((i < j) ? i : j)
}
/* 用c#可以:*/
void swap (object a, object b)
{
return ((i < j) ? i : j);
}
/* 我想大家一定看出来第二个例子要比较一个int和一个float的话,还需要一些转换,而第三个
例子就可以比较所有的变量!这个灵活度简直太大了。所以,我私以为,大家使用时一定要小心!
它在比较一个int和一个class的时候决不会报错的。呵呵,我发现我的翻译总是越跑越远,总是
扣不住原文。篡改甚多,敬请原谅!<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
赶出一编!请指正! 1。6 统一系统类型(Type system unification)
c#独创了一种类型——统一系统类型(为了这个累刑,我头疼死了。谁有更好的名字,请务必告诉
我)。总之,所有的其他类型,包括值和引用,都可以被当作统一系统类型来对待。从概念上说,
所有的类型都从它派生。这样,其他的类型就可以使用统一系统类型的属性和方法。包括一些“简
单”类型,如:int。还是给个例子吧:*/
using System;
class Test
{
static void Main() {
Console.WriteLine(3.ToString());
}
}
/*“3.ToString()”调用了object的“ToString()”方法。相信学过c/c++的朋友都知道要输出一个
数字有多麻烦,现在就省事了。再看一个:*/
class Test
{
static void Main() {
int i = 123;
object o = i; // boxing
int j = (int) o; // unboxing
}
}
/* 这个像帽子戏法的例子中,从“int”转换成“object”,又转换回来。这样一来,在值和引用
之间就架起了一座桥梁。这样有什么用呢。即兴举一个常见的例子...就min把。在c/c++中:*/
// c/c++ code
void min(int i, int j)
{
return ((i < j) ? i : j);
}
/* 如果比较的不是int,或者说可能是int,也可能是float、double呢?可以这样:*/
template<class T>
T min (T i, T j)
{
return ((i < j) ? i : j)
}
/* 用c#可以:*/
void swap (object a, object b)
{
return ((i < j) ? i : j);
}
/* 我想大家一定看出来第二个例子要比较一个int和一个float的话,还需要一些转换,而第三个
例子就可以比较所有的变量!这个灵活度简直太大了。所以,我私以为,大家使用时一定要小心!
它在比较一个int和一个class的时候决不会报错的。呵呵,我发现我的翻译总是越跑越远,总是
扣不住原文。篡改甚多,敬请原谅!<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- Beginner with c# 6
- Beginner with c# 2
- Beginner with C#
- Beginner with c# 3
- Beginner with c# 4
- Beginner with c# 7
- Spark Beginner with Recommended System
- Beginner
- Beginner
- C# 3.0: A Beginner's Guide
- C# 3.0: A Beginner's Guide
- Spring MVC beginner tutorial with Spring Tool Suite IDE
- Penetration Testing Skills Practice with Metasploitable (Beginner Guide)
- C# 3.0: A Beginner's Guide英文版
- C# WPF tutorial 2: Media player (beginner)视频教程
- OpenCms8创建模板指南(Beginner's guide to template creation with OpenCms 8)
- A Beginner Tutorial for Writing Simple COM/ATL DLL and Using it with .NET
- linux beginner
- refactory(重构)C++工具之随想
- The Future According to ASP+
- Beginner with c# 2
- 在ASP中调用存储过程的几种方法
- 爱君
- Beginner with c# 6
- 解决 ResultSet may only be accessed in a forward direction 错误
- SOA面向服务的架构
- T—SQL编程
- [原创] Questioning C# (二)
- IE下的脚本调试器的安装
- 关于c#中的消息处理函数和vc中的消息处理函数区别
- MS SQL Server中的CONVERT日期格式化大全
- 好的方法