using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ex13Operations1
{
public class Operations
{
public static double Addition(double x, double y)
{
return x + y;
}
public static double Subtraction(double x, double y)
{
return x - y;
}
public static double Multiplication(double x, double y)
{
return x * y;
}
public static double Division(double x, double y)
{
if (y == 0) return 0;
return x / y;
}
}
}
修改輸出DLL名稱
===================================================================
新增Console專案ex13CallOperation1DLL
目的:測試剛才建立DLL
加入參考
選擇Operations1.dll所在路徑
C:\Users\ryanwang\Documents\Visual Studio 2008\Projects\ex13Operations1\ex13Operations1\bin\Release
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ex13Operations1;
namespace ex13CallOperation1DLL
{
class Program
{
static void Main(string[] args)
{
double num1 = 1.5;
double num2 = 2.3;
double result;
result = Operations.Addition(num1, num2);
Console.WriteLine("{0} + {1} = {2}\n", num1, num2, result);
Console.ReadLine();
}
}
}
==================================================================
加入一個新method至Operations類別
public static void RandSeq(int number, int maxValue, out int []sequence)
{
sequence = new int[number];
Random rand = new Random();
for (int i = 0; i < number; i++)
sequence[i] = rand.Next(maxValue);
}
回主程式
int[] seq;
int number = 10;
int maxValue = 10;
Operations.RandSeq(number, 100, out seq);
for (int i = 0; i < number; i++)
Console.WriteLine("seq[{0}]={1}", i, seq[i]);