跳转到内容

不完全类型:修订间差异

维基百科,自由的百科全书
删除的内容 添加的内容
ShiningRay留言 | 贡献
无编辑摘要
 
ShiningRay留言 | 贡献
无编辑摘要
第1行: 第1行:
In [[computing]], a '''partial type''' is a [[data type]] definition which spans multiple source code files. In [[object orientated programming]] this may be necessary for a variety of reasons: performance and cost can often prohibit the use of several separate classes; the use of code generating tools is increasing, and it is convenient to separate machine generated code from code written by the programmer.
在[[计算]]中,一个'''不完全类型'''是一种特殊的[[数据类型]],它的定义会跨越多个源文件。在[[面向对象编程]]中会由于一些不同的原因用到:性能和成本常常会In [[computing]], a '''partial type''' is a [[data type]] definition which spans multiple source code files. In [[object orientated programming]] this may be necessary for a variety of reasons: performance and cost can often prohibit the use of several separate classes; the use of code generating tools is increasing, and it is convenient to separate machine generated code from code written by the programmer.


Partial types are a feature of the C# 2.0 language. The syntax for creating a partial class definition is as follows:
不完全类型是C# 2.0的一个特性。用于建立一个不完全类定义的语法如下:Partial types are a feature of the C# 2.0 language. The syntax for creating a partial class definition is as follows:


'''SourceFile1.cs'''
'''SourceFile1.cs'''
第27行: 第27行:
</code>
</code>


在 C# 2.0之前的版本,这会造成一个编译错误,因为同样的类重复定义了两次(同样也因为<code>partial</code>关键字)。在C#2.0中,它会被看作为一个单一的类定义。其它C#2.0的新特性包括[[匿名方法]]、[[迭代子]]和[[泛型]](类似于C++中的[[模板]])。
In C# versions before 2.0, this would cause a compiler error because the same class appears to be defined twice (and also because of the <code>partial</code> keyword). In C# 2.0 this is treated as a single class definition. Other new features of C# 2.0 include [[anonymous methods]], [[iterator]]s and [[generics]] (similar to templates in C++).


The use of partial classes has no effect on generated code (unless editor meta-data is emitted).
使用不完全类对生成的代码没有任何影响((unless editor meta-data is emitted).


[[Category:Object-oriented programming]]
[[Category:面向对象编程]]
[[Category:数据类型]]
[[Category:数据类型]]
[[en:Partial type]]
[[en:Partial type]]

2005年8月10日 (三) 13:32的版本

计算中,一个不完全类型是一种特殊的数据类型,它的定义会跨越多个源文件。在面向对象编程中会由于一些不同的原因用到:性能和成本常常会In computing, a partial type is a data type definition which spans multiple source code files. In object orientated programming this may be necessary for a variety of reasons: performance and cost can often prohibit the use of several separate classes; the use of code generating tools is increasing, and it is convenient to separate machine generated code from code written by the programmer.

不完全类型是C# 2.0的一个特性。用于建立一个不完全类定义的语法如下:Partial types are a feature of the C# 2.0 language. The syntax for creating a partial class definition is as follows:

SourceFile1.cs

public partial class ExampleClass
{
   public void SomeFunction()
   {
       // ...
   }
}

SourceFile2.cs

public partial class ExampleClass
{
   public void SomeOtherFunction()
   {
       // ...
   }
}

在 C# 2.0之前的版本,这会造成一个编译错误,因为同样的类重复定义了两次(同样也因为partial关键字)。在C#2.0中,它会被看作为一个单一的类定义。其它C#2.0的新特性包括匿名方法迭代子泛型(类似于C++中的模板)。

使用不完全类对生成的代码没有任何影响((unless editor meta-data is emitted).