Concept

C Sharp 2.0

Summary
The computer programming language, C#, introduces several new features in version 2.0 (corresponding to the 3rd edition of the ECMA-334 standard and the .NET Framework 2.0). These include: Partial classes allow implementation of a class to be spread between several files, with each file containing one or more class members. It is useful primarily when parts of a class are generated automatically. For example, the feature is heavily used by code-generating user interface designers in Visual Studio. file1.cs: public partial class MyClass { public void MyMethod1() { // Manually written code } } file2.cs: public partial class MyClass { public void MyMethod2() { // Automatically generated code } } Generics, or parameterized types, or parametric polymorphism is a .NET 2.0 feature supported by C# and Visual Basic. Unlike C++ templates, .NET parameterized types are instantiated at runtime rather than by the compiler; hence they can be cross-language whereas C++ templates cannot. They support some features not supported directly by C++ templates such as type constraints on generic parameters by use of interfaces. On the other hand, C# does not support non-type generic parameters. Unlike generics in Java, .NET generics use reification to make parameterized types first-class objects in the CLI Virtual Machine, which allows for optimizations and preservation of the type information. Static classes are classes that cannot be instantiated or inherited from, and that only allow static members. Their purpose is similar to that of modules in many procedural languages. The .NET 2.0 Framework allowed C# to introduce an iterator that provides generator functionality, using a yield return construct similar to yield in Python. With a yield return, the function automatically keeps its state during the iteration. // Method that takes an iterable input (possibly an array) // and returns all even numbers. public static IEnumerable GetEven(IEnumerable numbers) { foreach (int i in numbers) { if (i % 2 == 0) yield return i; } } There is also a yield break statement, in which control is unconditionally returned to the caller of the iterator.
About this result
This page is automatically generated and may contain information that is not correct, complete, up-to-date, or relevant to your search query. The same applies to every other page on this website. Please make sure to verify the information with EPFL's official sources.