ylbtech-Microsoft-CSharpSamples:ylbtech-LanguageSamples-PartialTypes(部分类型)
1.A,示例(Sample) 返回顶部

“分部类型”示例

本示例演示了如何使用允许在两个或更多 C# 文件中定义类或结构的分部类型。这就允许多个程序员并行处理一个类的不同部分,并将复杂类的不同方面保存在不同的文件中。

安全说明

提供此代码示例是为了阐释一个概念,它并不代表最安全的编码实践,因此不应在应用程序或网站中使用此代码示例。对于因将此代码示例用于其他用途而出现的偶然或必然的损害,Microsoft 不承担任何责任。

在 Visual Studio 中生成并运行“分部类型代码”示例

  • 在“调试”菜单中,单击“开始执行(不调试)”。

从命令行生成并运行“分部类型代码”示例

  1. 使用“更改目录(cd)”命令转到“PartialTypes”目录。

  2. 键入以下命令:

    csc PartialTypes.cs
    PartialTypes
1.B,示例代码(Sample Code)返回顶部

1.B.1, CharPartialPrivate.cs

// 版权所有(C) Microsoft Corporation。保留所有权利。
// 此代码的发布遵从
// Microsoft 公共许可(MS-PL,http://opensource.org/licenses/ms-pl.html)的条款。
//
//版权所有(C) Microsoft Corporation。保留所有权利。 using System;
using System.Collections.Generic;
using System.Text; namespace PartialClassesExample
{
// 使用 partial 关键字可以在其他 .cs 文件中定义
// 此类的附加方法、字段和属性。
// 此文件包含 CharValues 定义的私有方法。
partial class CharValues
{
private static bool IsAlphabetic(char ch)
{
if (ch >= 'a' && ch <= 'z')
return true;
if (ch >= 'A' && ch <= 'Z')
return true;
return false;
} private static bool IsNumeric(char ch)
{
if (ch >= '' && ch <= '')
return true;
return false;
}
}
}

1.B.2, ChartPartialPublic.cs

// 版权所有(C) Microsoft Corporation。保留所有权利。
// 此代码的发布遵从
// Microsoft 公共许可(MS-PL,http://opensource.org/licenses/ms-pl.html)的条款。
//
//版权所有(C) Microsoft Corporation。保留所有权利。 using System;
using System.Collections.Generic;
using System.Text; namespace PartialClassesExample
{
// 使用 partial 关键字可以在其他 .cs 文件中定义
// 此类的附加方法、字段和属性。
// 此文件包含 CharValues 定义的公共方法。
partial class CharValues
{
public static int CountAlphabeticChars(string str)
{
int count = ;
foreach (char ch in str)
{
// IsAlphabetic 是在 CharTypesPrivate.cs 中定义的
if (IsAlphabetic(ch))
count++;
}
return count;
}
public static int CountNumericChars(string str)
{
int count = ;
foreach (char ch in str)
{
// IsNumeric 是在 CharTypesPrivate.cs 中定义的
if (IsNumeric(ch))
count++;
}
return count;
} }
}

1.B.3, PartialTypes.cs

// 版权所有(C) Microsoft Corporation。保留所有权利。
// 此代码的发布遵从
// Microsoft 公共许可(MS-PL,http://opensource.org/licenses/ms-pl.html)的条款。
//
//版权所有(C) Microsoft Corporation。保留所有权利。 using System;
using System.Collections.Generic;
using System.Text; namespace PartialClassesExample
{
class PartialClassesMain
{
static void Main(string[] args)
{
if (args.Length != )
{
Console.WriteLine("One argument required.");
return;
} // CharValues 是一个分部类 -- 该分部类有两个方法
// 是在 CharTypesPublic.cs 中定义的,另有两个方法是在
// CharTypesPrivate.cs 中定义的。
int aCount = CharValues.CountAlphabeticChars(args[]);
int nCount = CharValues.CountNumericChars(args[]); Console.Write("The input argument contains {0} alphabetic and {1} numeric characters", aCount, nCount);
}
}
}

1.B.4,

1.C,下载地址(Free Download)返回顶部
作者:ylbtech
出处:http://ylbtech.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

最新文章

  1. HDU 1075 What Are You Talking About(Trie的应用)
  2. Tomcat Nginx cluster note
  3. ios 企业发布
  4. NetAdvantage 笔记
  5. F - Truck History - poj 1789
  6. IdentityServer(12)- 使用 ASP.NET Core Identity
  7. awk 的 pattern(模式)
  8. socks-proxy---with ssh
  9. ESP8266 软件实现 Delta-sigma(ΔΣ)调制器 并通过I2S接口输出编码流
  10. Java基础 - 线程(一)
  11. 了解java虚拟机—G1回收器(9)
  12. centos chroot使用
  13. 使用ShareSDK完成第三方(QQ、微信、微博)登录和分享
  14. NodeJS学习笔记六
  15. Application Loader上传app,一直卡在“正在通过 App Store 进行鉴定”
  16. C# 使用int.TryParse,Convert.ToInt32,(int)将浮点类型转换整数时的区别
  17. simulink pi的方法产生锁相环
  18. ListView实现分页加载(三)实现分页加载
  19. 【poj Roads in the North】 题解
  20. 将list集合,元素随机打乱

热门文章

  1. mac date 和 Linux date实现从指定时间开始循环
  2. hdu 1269 迷宫城堡(Targin算法)
  3. [转载] Python itertools模块详解
  4. Windows7 + OSG3.6 + VS2017 + Qt5.11
  5. 关于Sphinx中使用 RealTime Index的问题
  6. echarts官网上的动态加载数据bug被我解决。咳咳/。
  7. lr_Vugen界面图
  8. mybatis 报错: Invalid bound statement (not found)
  9. vmware漏洞之三——Vmware虚拟机逃逸漏洞(CVE-2017-4901)Exploit代码分析与利用
  10. CodeForces 723F st-Spanning Tree