Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > .NET > C#.NET > 从vc++ 到 visual c#.net
【标  题】:从vc++ 到 visual c#.net
【关键字】:vc++,visual,c#.net
【来  源】:http://blog.csdn.net/lucky2all/archive/2007/04/17/1568132.aspx

从vc++ 到 visual c#.net

Your Ad Here

从vc++ 到 visual c#.net

lucky2all@gmail.com

抛去他们之间概念与基础层面的差别,只是从设计,实现角度来比较他们之间的异同点,
能够从vc++顺利的过渡到C#.net.


在mfc中我们一般从窗口 CWnd, 基础类CObject的几大特性,消息机制,对象之间的继承关系,多线程的同步互斥来理解
mfc中间的机理,然后到模仿,设计,编写自己的类库。

在C#中,我们同样也可以从 WinForm, Object基础类,事件,对象之间的关系,多线程的同步互斥来学习。

1. System.Windows.Forms.Form
   
Toolbox/Properties的配合,使设计满意的Form变得简单。

2. Object

可以从他的metadata中的summary来理解,至于c#为何在他的基础类中提供这些方法,我们可以在实践中体会。
namespace System
{
    // Summary:
    //     Supports all classes in the .NET Framework class hierarchy and provides low-level
    //     services to derived classes. This is the ultimate base class of all classes
    //     in the .NET Framework; it is the root of the type hierarchy.
    [Serializable]
    [ComVisible(true)]
    [ClassInterface(2)]
    public class Object
    {
        // Summary:
        //     Initializes a new instance of the System.Object class.
        [ReliabilityContract(3, 1)]
        public Object();

        // Summary:
        //     Determines whether the specified System.Object is equal to the current System.Object.
        //
        // Parameters:
        //   obj:
        //     The System.Object to compare with the current System.Object.
        //
        // Returns:
        //     true if the specified System.Object is equal to the current System.Object;
        //     otherwise, false.
        public virtual bool Equals(object obj);
        //
        // Summary:
        //     Determines whether the specified System.Object instances are considered equal.
        //
        // Parameters:
        //   objB:
        //     The second System.Object to compare.
        //
        //   objA:
        //     The first System.Object to compare.
        //
        // Returns:
        //     true if objA is the same instance as objB or if both are null references
        //     or if objA.Equals(objB) returns true; otherwise, false.
        public static bool Equals(object objA, object objB);
        //
        // Summary:
        //     Serves as a hash function for a particular type. System.Object.GetHashCode()
        //     is suitable for use in hashing algorithms and data structures like a hash
        //     table.
        //
        // Returns:
        //     A hash code for the current System.Object.
        public virtual int GetHashCode();
        //
        // Summary:
        //     Gets the System.Type of the current instance.
        //
        // Returns:
        //     The System.Type instance that represents the exact runtime type of the current
        //     instance.
        public Type GetType();
        //
        // Summary:
        //     Creates a shallow copy of the current System.Object.
        //
        // Returns:
        //     A shallow copy of the current System.Object.
        protected object MemberwiseClone();
        //
        // Summary:
        //     Determines whether the specified System.Object instances are the same instance.
        //
        // Parameters:
        //   objB:
        //     The second System.Object to compare.
        //
        //   objA:
        //     The first System.Object to compare.
        //
        // Returns:
        //     true if objA is the same instance as objB or if both are null references;
        //     otherwise, false.
        [ReliabilityContract(3, 2)]
        public static bool ReferenceEquals(object objA, object objB);
        //
        // Summary:
        //     Returns a System.String that represents the current System.Object.
        //
        // Returns:
        //     A System.String that represents the current System.Object.
        public virtual string ToString();
    }
}


3. 继承关系

C# 中不存在多继承,
 class A
{
}

class B{}

class C : A, B {}
是不会在C#中出现的,在C++的多继承一般也用的很少,理解起来也比较麻烦。

但C#中,

如果class B 为一个interface
interface _B {}

则子类c可以这样定义 class c : A, _B {}, 这样也达到了多继承的效果。

c#中public, protected, private的继承关系与c++是一致的。

static 函数/变量 的用法也相同。

virtual 的用法也是一致的,纯虚的定义有点差别c#中是 abstract virtual method(); c++中是 virtual method() =0;

C#中类可以被定为sealed属性类,表明他不能再被继承了,
这有点类似c++中如果一个类的析构函数如果不是virtual, 那么它就告诉你,最好不要继承我了。



4.事件

c#中可以通过 +=, -=来添加,去除多个事件处理体,非常方便。

5.线程同步/互斥

c#中 Thread来创建一个线程

Thread t1 = new Thread (new ThreadStart (Func))

通过 ReaderWriterLock,  Mutex, Monitor, Interlocked, AutoResetEvent等来同步互斥,

与c++的 mutex, event, Critical_Section等类似,不过更清晰。


6.Web service
C#可作为web的设计语言,vs2005在设计/发布方面都有很好的支持。

7.Enterprise lib
open source, 提炼的企业级开发库,很有用,根据需要自己定制。

8.其它

clickonce发布,ado.net/smartclient等,慢慢体验。 

 

Visual C++文件操作:【上一篇】
DataList绑定多维数组的问题和解决方案:【下一篇】
【相关文章】
  • Visual C++文件操作
  • Visual Studio2005或在asp.net中常碰到的问题:未能创建Mutex,重新把ASP.NET 2.0注册到IIS中,IIS_WPG的权限
  • 使用Visual Studio2005入门asp.Net2.0系列视频教程
  • Visual Studio 2005入门 之 控制结构一(分支)
  • Visual Studio 2005入门 之 控制结构一(循环)[视频]
  • Visual Studio 2005入门 之 Asp.Net中的事件(页面事件)[视频]
  • Visual Studio 2005入门 之 Asp.Net中的事件(控件事件) [视频]
  • Visual Studio 2005入门 之 第四章小结测试[视频]
  • Visual Studio 2005入门 之 类的概述[视频]
  • Visual Studio 2005入门 之 类的自定义事件[视频]
  • 【随机文章】
  • system 函数[转自第2学堂]
  • FreeBSD下的字符终端的vi使用中文
  • IBM RS6000巡检流程
  • 用PHP开发健壮的代码(二):有效地使用变量
  • 多进程的构架方法
  • Nutch 0.8笔记(1)--必知必会
  • Microsoft Visual C++ 6.0 SP6 resource compiler buffer overflow
  • 建立无模式窗口
  • java类加载原理分析
  • 策略游戏 图
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.