网站导航免费论文 原创论文 论文搜索 原创论文 网学软件 学术大家 资料中心 会员中心 问题解答 原创论文 论文素材 设计下载 最新论文 下载排行 论文上传 在线投稿 联系我们
返回网学首页
网学联系
最新论文 推荐专题 热门论文 素材专题
当前位置: 网学 > 编程文档 > C# > 正文
写给转向C#的C++程序员的C# FAQ
来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/14
下载{$ArticleTitle}原创论文样式
生成如下输出:
fred is not an integer 
10 is an integer
5.2 可以在运行时获取类型的名称吗? 可以。使用object类的GetType方法就可以获得该对象所属类型的名称。例如:
using System; 
 
class CTest
{
          class CApp 
          {
                    public static void Main()
                    { 
                          long i = 10; 
                          CTest ctest = new CTest(); 
 
                          DisplayTypeInfo( ctest ); 
                          DisplayTypeInfo( i ); 
                    }
                
                    static void DisplayTypeInfo( object obj ) 
                    { 
                          Console.WriteLine( "Type name = {0}, full type name = {1}", obj.GetType(), obj.GetType().FullName ); 
                    }
          }
}
会生成下列输出:
Type name = CTest, full type name = CTest 
Type name = Int64, full type name = System.Int64
6. 高级语言特性 6.1 什么是委托? 所谓委托(delegate),是从System.Delegate类派生而来的一个类。但是,C#语言对委托的声明提供了特殊的语法,使得它们看起来并不像是类。一个委托表现了一个特定签名的方法,委托的一个实例则表现了特定对象(或类,如果方法是静态方法的话)中拥有特定签名的方法。例如:
using System;
delegate void Stereotype();
 
class CAmerican 
{
          public void BePatriotic() 
          { 
                    Console.WriteLine( " <gulp>  God bless America.");
          }
} 
 
class CBrit
{
          public void BeXenophobic()
          {
                    Console.WriteLine( "Bloody foreigners  " );
          }
}
 
class CApplication
{ 
          public static void RevealYourStereotype( Stereotype stereotypes )
          { 
                    foreach( Stereotype s in stereotypes ) 
                          s();
          }
          
          public static void Main() 
          {
                    CAmerican chuck = new CAmerican(); 
                    CBrit edward = new CBrit(); 
 
                    // Create our list of sterotypes.
                    Stereotype stereotypes = new Stereotype;
                    stereotypes[0] = new Stereotype( chuck.BePatriotic );
                    stereotypes = new Stereotype( edward.BeXenophobic );
                
                    // Reveal yourselves!
                    RevealYourStereotype(stereotypes ); 
          } 
}

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号