Step1 :Create a C sharp DLL project like below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SimpleMathLib
{
public class MathDll
{
public MathDll()
{
}
public static int Sum(int a, int b)
{
return a + b;
}
public int Mul(int a, int b)
{
return a * b;
}
}
}
Step 2: Use Powershell to load and use this class:
#Load Simple Math Dll.
[Reflection.Assembly]::LoadFile("C:\Users\zhangwe\Documents\Visual Studio 2010\Projects\SimpleMathLib\SimpleMathLib\bin\Debug\SimpleMathLib.dll")
#Use static class method.
[SimpleMathLib.MathDll]::Sum(1,2)
#New an object
$mathInstance = New-Object SimpleMathLib.MathDll
$mathInstance.Mul(2,3)

本文介绍了一个简单的 C# DLL 项目的创建过程及通过 PowerShell 加载和使用该 DLL 中的方法。演示了如何实现基本数学运算,包括求和和乘法。
1539

被折叠的 条评论
为什么被折叠?



