ylbtech-Microsoft-CSharpSamples:ylbtech-LanguageSamples-Libraries(库)
1.A,示例(Sample) 返回顶部

“库”示例

本示例演示如何用 C# 中创建和使用 DLL。

安全说明

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

在 Visual Studio 中生成并运行“库”示例

  1. 在“解决方案资源管理器”中,右击“FunctionTest”项目并单击“设为启动项目”。

  2. 在“解决方案资源管理器”中,右击“FunctionTest”项目并单击“属性”。

  3. 打开“配置属性”文件夹并单击“调试”。

  4. 在“命令行参数”属性中,输入 3 5 10

  5. 单击“确定”。

  6. 在“调试”菜单中,单击“开始执行(不调试)”。这将自动在“Functions”目录中生成库并执行程序。

从命令行生成并运行“库”示例

  1. 使用“更改目录”命令转到“Functions”目录。

  2. 键入以下命令:

    csc /target:library /out:Functions.dll Factorial.cs DigitCounter.cs
  3. 使用“更改目录”命令转到“FunctionTest”目录。

  4. 键入以下命令:

    copy ..\Functions\Functions.dll .
    csc /out:FunctionTest.exe /R:Functions.DLL FunctionClient.cs
    FunctionTest 3 5 10
1.B,示例代码(Sample Code)返回顶部

1.B.1, DigiCounter.cs

// 版权所有(C) Microsoft Corporation。保留所有权利。
// 此代码的发布遵从
// Microsoft 公共许可(MS-PL,http://opensource.org/licenses/ms-pl.html)的条款。
//
//版权所有(C) Microsoft Corporation。保留所有权利。 // DigitCounter.cs
// 编译时使用:/target:library
using System; // 声明与 Factorial.cs 中的命名空间相同的命名空间。这样仅允许将
// 类型添加到同一个命名空间中。
namespace Functions
{
public class DigitCount
{
// NumberOfDigits 静态方法计算
// 传递的字符串中数字字符的数目:
public static int NumberOfDigits(string theString)
{
int count = ;
for ( int i = ; i < theString.Length; i++ )
{
if ( Char.IsDigit(theString[i]) )
{
count++;
}
}
return count;
}
}
}

1.B.2, Facotrial.cs

// 版权所有(C) Microsoft Corporation。保留所有权利。
// 此代码的发布遵从
// Microsoft 公共许可(MS-PL,http://opensource.org/licenses/ms-pl.html)的条款。
//
//版权所有(C) Microsoft Corporation。保留所有权利。 // Factorial.cs
// 编译时使用:/target:library
using System; // 声明命名空间。需要根据
// 库的命名空间打包库,以便 .NET 运行时可以正确地加载类。
namespace Functions
{
public class Factorial
{
// “Calc”静态方法为传入的指定整数
// 计算阶乘值:
public static int Calc(int i)
{
return((i <= ) ? : (i * Calc(i-)));
}
}
}

1.B.3,

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

1.B.1, FunctionClient.cs

// 版权所有(C) Microsoft Corporation。保留所有权利。
// 此代码的发布遵从
// Microsoft 公共许可(MS-PL,http://opensource.org/licenses/ms-pl.html)的条款。
//
//版权所有(C) Microsoft Corporation。保留所有权利。 // FunctionClient.cs
// 编译时使用:/reference:DigitCounter.dll;Factorial.dll
// 参数:3 5 10
using System;
// 下面的 using 指令使 Functions
// 命名空间中定义的类型可用于此编译单元:
using Functions;
class FunctionClient
{
public static void Main(string[] args)
{
Console.WriteLine("Function Client"); if ( args.Length == )
{
Console.WriteLine("Usage: FunctionTest ... ");
return;
} for ( int i = ; i < args.Length; i++ )
{
int num = Int32.Parse(args[i]);
Console.WriteLine(
"The Digit Count for String [{0}] is [{1}]",
args[i],
// 调用 DigitCount 类中的
// NumberOfDigits 静态方法:
DigitCount.NumberOfDigits(args[i]));
Console.WriteLine(
"The Factorial for [{0}] is [{1}]",
num,
// 调用 Factorial 类中的 Calc 静态方法:
Factorial.Calc(num) );
}
}
}

1.B.2,

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

ylbtech-LanguageSamples-Libraries(库)的更多相关文章

  1. 012.CI4框架CodeIgniter, 加载并调用自己的Libraries库

    01. 在Libraries目录创建一个Mylib文件,内容是一个简单的类 <?php namespace App\Controllers; class Home extends BaseCon ...

  2. Qt 添加Includes、Libraries库

    1 #------------------------------------------------- # # 加载相机SDK-Includes-Libraries # #------------- ...

  3. 9.Libraries and visibility 库和可见性

    import和liabrary指令可以帮助你创建模块化,可复用的代码.库不仅仅提供API,也是一个私有化单元:库中已下划线(_)开头的类都是对外不可访问的.每个Dart的应用也是一个包,尽管它没有使用 ...

  4. 大型项目 Gradle 的常用库和版本管理[转]

    http://www.tuicool.com/articles/vqQZBrm 大型项目 Gradle 的常用库和版本管理 时间 2016-03-15 06:44:00  Mystra 原文  htt ...

  5. 所有selenium相关的库

    通过爬虫 获取 官方文档库 如果想获取 相应的库 修改对应配置即可 代码如下 from urllib.parse import urljoin import requests from lxml im ...

  6. java常用英文解释

    java常用名词解释: OO: object-oriented ,面向对象 OOP:object-oriented programming,面向对象编程 Author:JCC Object:对象JDK ...

  7. windows 下 gvim/vim lua支持问题,neocomplete等插件支持

    此文是按照知乎 https://www.zhihu.com/question/29333426 "windows下vim的lua支持问题?" 一文汇总的解决方案. 题主提供了不错的 ...

  8. Java基础常见英语词汇

    Java基础常见英语词汇(共70个) ['ɔbdʒekt] ['ɔ:rientid]导向的                             ['prəʊɡræmɪŋ]编程 OO: object ...

  9. Idea15/16 配置Tomcat

    1:我这里使用的是Eclipse创建的项目,导出后导入到Idea中使用 2:Idea导入Eclipse项目 3:Idea项目配置(默认快捷键CTRL+SHIT+ALT+S) 3.1 Project 项 ...

  10. 安卓系统源码编译系列(六)——单独编译内置浏览器WebView教程

    原文                   http://blog.csdn.net/zhaoxy_thu/article/details/18883015                 本文主要对从 ...

随机推荐

  1. ES Java 客户端

    标签(空格分隔): ES Java 客户端 节点客户端(node client): 节点客户端本身也是一个ES节点(一般不保存数据,不能成为主节点),它能以无数据节点身份加入到集群中.因为它是集群环境 ...

  2. 升级PIP源

    pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple django

  3. 访问Github慢的解决办法

    http://blog.csdn.net/sunsteam/article/details/63253933 http://tool.chinaz.com/dns 151.101.196.249  g ...

  4. webpy 上传文件

    x = web.input(myfile={})是一个类字典对象,会返回所有GET或POST的数据 括号内部用来设置myfile的默认值,以防请求中根本就没有myfile键 定义如下一个表单 form ...

  5. C/C++ 基础知识

    C/C++ 基础知识 C 语言优秀学习网站 [C Programming Language] C 语言的注释 单行注释 /* comment goes here */ // comment goes ...

  6. python之md5模块

    python的md5模块使用非常简单,包括以下几个函数: md5.new([arg]) 返回一个md5对象,如果给出参数,则相当于调用了update(arg) md5.updte(arg) 用stri ...

  7. Codeforces 1082 C. Multi-Subject Competition-有点意思 (Educational Codeforces Round 55 (Rated for Div. 2))

    C. Multi-Subject Competition time limit per test 2 seconds memory limit per test 256 megabytes input ...

  8. ZOJ 3872 Beauty of Array【无重复连续子序列的贡献和/规律/DP】

    Edward has an array A with N integers. He defines the beauty of an array as the summation of all dis ...

  9. 2018 ACM-ICPC 焦作网络赛

    Problem A Problem B 简单题,做下背包就好了. Problem C Problem D Problem E Problem F Problem G Problem H Problem ...

  10. oracle substr

    SUBSTR( string, start_position [, length ] ) Parameters or Arguments string The source string. start ...