ylbtech-LanguageSamples-PartialTypes(部分类型)
| ylbtech-Microsoft-CSharpSamples:ylbtech-LanguageSamples-PartialTypes(部分类型) |
| 1.A,示例(Sample) 返回顶部 |
“分部类型”示例
本示例演示了如何使用允许在两个或更多 C# 文件中定义类或结构的分部类型。这就允许多个程序员并行处理一个类的不同部分,并将复杂类的不同方面保存在不同的文件中。
| 安全说明 |
|---|
|
提供此代码示例是为了阐释一个概念,它并不代表最安全的编码实践,因此不应在应用程序或网站中使用此代码示例。对于因将此代码示例用于其他用途而出现的偶然或必然的损害,Microsoft 不承担任何责任。 |
在 Visual Studio 中生成并运行“分部类型代码”示例
在“调试”菜单中,单击“开始执行(不调试)”。
从命令行生成并运行“分部类型代码”示例
使用“更改目录(cd)”命令转到“PartialTypes”目录。
键入以下命令:
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/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 |
ylbtech-LanguageSamples-PartialTypes(部分类型)的更多相关文章
- C#中的枚举类型(enum type)
ylbtech 原文 C#中的枚举类型(enum type) 概念 枚举类型(enum type)是具有一组命名常量的独特的值类型.在以下示例中: enum Color { Red, Green, B ...
- C#中的值类型(value type)与引用类型(reference type)的区别
ylbtech- .NET-Basic:C#中的值类型与引用类型的区别 C#中的值类型(value type)与引用类型(reference type)的区别 1.A,相关概念返回顶部 C#中 ...
- Error-MVCr:找到了多个与 URL 匹配的控制器类型。如果多个控制器上的特性路由与请求的 URL 匹配,则可能会发生这种情况。
ylbtech-Error-MVCr:找到了多个与 URL 匹配的控制器类型.如果多个控制器上的特性路由与请求的 URL 匹配,则可能会发生这种情况. 1.返回顶部 1. 找到了多个与 URL 匹配的 ...
- 分析器错误消息: 未能找到 CodeDom 提供程序类型
ylbtech-Error-WebForm:分析器错误消息: 未能找到 CodeDom 提供程序类型“Microsoft.CodeDom.Providers.DotNetCompilerPlatfor ...
- HTML5: input:file上传类型控制
ylbtech-HTML5: input:file上传类型控制 1. 一.input:file 属性返回顶部 一.input:file属性 属性值有以下几个比较常用: accept:表示可以选择的 ...
- ylbtech-LanguageSamples-Nullable(可以为 null 的类型)
ylbtech-Microsoft-CSharpSamples:ylbtech-LanguageSamples-Nullable(可以为 null 的类型) 1.A,示例(Sample) 返回顶部 “ ...
- Java-Runoob:Java 变量类型
ylbtech-Java-Runoob:Java 变量类型 1.返回顶部 1. Java 变量类型 在Java语言中,所有的变量在使用前必须声明.声明变量的基本格式如下: type identifie ...
- 杂项:MIME(多用途互联网邮件扩展类型)百科
ylbtech-杂项:MIME(多用途互联网邮件扩展类型)百科 MIME(Multipurpose Internet Mail Extensions)多用途互联网邮件扩展类型.是设定某种扩展名的文件用 ...
- C# 中的结构类型(struct type)
ylbtech- .NET-Basic:C# 中的结构类型(struct type) C# 中的结构类型(struct type) 1.A,相关概念返回顶部 像类一样,结构(struct)是能够包 ...
随机推荐
- JS实现全选与取消 Jquery判断checkbox是否被选中
1.JS实现checkbox全选与取消 <body> <input type="checkbox" name="select_all"/> ...
- 8:django sessions(会话)
django会话 django提供对匿名会话全方位的支持,会话框架可以存储和检索每个站点访问者的任意数据.会话数据是存储在服务器端的,并且简要了发送和接受cookie的过程,cookies只包含一个s ...
- linux命令(41):watch命令
watch是一个非常实用的命令,基本所有的Linux发行版都带有这个小工具,如同名字一样,watch可以帮你监测一个命令的运行结果,省得你一遍遍的手动运行.在Linux下,watch是周期性的执行下个 ...
- Windows + IDEA 手动开发MapReduce程序
参见马士兵老师的博文:map_reduce 环境配置 Windows本地解压Hadoop压缩包,然后像配置JDK环境变量一样在系统环境变量里配置HADOOP_HOME和path环境变量.注意:hado ...
- hdu 2444(染色法判断二分图+最大匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- 596. Classes More Than 5 Students
There is a table courses with columns: student and class Please list out all classes which have more ...
- 多线程下,Python Sqlite3报[SQLite objects created in a thread can only be used...]问题
明明加了锁保护,还是出了下面的问题 ProgrammingError: SQLite objects created in a thread can only be used in that same ...
- python 重新执行循环中出错的那一次
# coding: utf-8 li = [1,2,3,4,5] for num in li: while True: try: # do something except some error: c ...
- PHP文件包含小结
协议 各种协议的使用有时是关键 file协议 file后面需是///,例如file:///d:/1.txt 也可以是file://e:/1.txt,如果是在当前盘则可以file:///1.txt 如果 ...
- CodeForces 734F Anton and School
位运算. 两个数的和:$A+B=(AandB)+(AorB)$,那么$b[i]+c[i]=n*a[i]+suma$.可以解出一组解,然后再按位统计贡献验证一下. #pragma comment(lin ...
