从vc++ 到 visual c#.net
2007-04-17 18:34
459 查看
从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等,慢慢体验。
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 Studio.NET的C#,VB.NET,VC++project工程转为NAnt Build的小程序(利用XSL)
- 从vc++ 到 visual c#.net (内存管理)
- 在Visual C# .Net 中怎样向Microsoft Excel 2002 传输XML数据[译]
- Visual C# .NET 中跟踪和调试
- Visual C#.Net网络程序设计-Tcp篇(2)
- Visual C#.Net网络程序开发之TCP/IP
- Visual C#.Net 网络程序开发-Socket篇
- "HOW TO: Create a Smooth Progress Bar in Visual C# .NET"的学习笔记
- HOW TO:使用 Visual C# .NET 在 ASP.NET 中创建自定义错误报告
- 利用 Visual C# .NET 和 asp .net 使 Word 自动新建文档
- [引]如何藉由使用 Visual C# . NET 處理 Word 中的事件
- Remote Data Access Synchronization with SQL Server 2005 Compact Edition and Visual C#.NET
- HOW TO:在 Visual C# .NET 中使用 System.Xml 合并两个 XML 文档中的数据
- 使用 Visual C# .NET 将字符串转换为小写、大写或词首字母大写
- 如何使用 Visual C# .NET 从 DataSet 对象更新数据库
- 利用 Visual C# .NET 使 Word 自动新建文档
- Visual C#.Net 网络程序开发-Socket篇第1/2页
- 怎样给listview的ColumnHeader 设置图像(in Visual C# .NET)
- Visual C#.Net 网络程序开发-Socket篇
- 如何使用 Visual C# .NET 处理 Excel 事件