标签:
7.1分部类型
7.1.1 在多个文件中创建一个类型
partial class Example<TFirst, TSecond> : IEquatable<string> where TFirst : class { public bool Equals(string other) { return false; } } partial class Example<TFirst, TSecond> : EventArgs, IDisposable { public void Dispose() { } }
7.1.2分部类型的使用 XAML
7.1.3 C#3.0 独有的分部方法
partial class PartialMethodDemo { public PartialMethodDemo() { OnConstructorStart(); Console.WriteLine("Generated constructor"); OnConstructorEnd(); } partial void OnConstructorStart(); partial void OnConstructorEnd(); } partial class PartialMethodDemo { partial void OnConstructorEnd() { Console.WriteLine("Manual code"); } }
7.2静态类型
public sealed class NonStaticStringHelper C#1.0的工具类 { private NonStaticStringHelper() { } public static string Reverse(string input) { char[] chars = input.ToCharArray(); Array.Reverse(chars); return new string(chars); } }
public static class StaticStringHelper //C#2.0工具类 { public static string Reverse(string input) { char[] chars = input.ToCharArray(); Array.Reverse(chars); return new string(chars); } }
7.3独立的取值方法/赋值方法属性访问器
7.4 命名空间别名
7.4.1限定的命名空间别名
using System; using System.ComponentModel; using WebForms = System.Web.UI.WebControls; using WinForms = System.Windows.Forms; namespace Chapter07 { [Description("Listing 7.05")] class SimpleAliases { static void Main() { Console.WriteLine (typeof (WinForms.Button)); Console.WriteLine (typeof (WebForms.Button)); } } }
标签:
原文地址:http://www.cnblogs.com/leonhart/p/4739325.html