using
System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace TestFuns
{
class Program
{
Functions#region Functions
/**//// <summary>
/// 数列
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
private static int numlist(int n){
if (n < 2)
return 1;
else
return numlist(n - 1) + numlist(n-2);
}
/**//// <summary>
/// 显示1-50随机数,各不相同
/// </summary>
private static void InsertRandomArr() {
int tmpNum=0;
ArrayList newarr = new ArrayList();
Random rd = new Random();
while (newarr.Count < 50) {
tmpNum = rd.Next(0, 51);
if (!newarr.Contains(tmpNum))
newarr.Add(tmpNum);
}
for (int i = 49; i > 0; i--) {
Console.Write(newarr[i].ToString()+" ");
}
}
#endregion
DelegateDemo#region DelegateDemo
public class ShowMsgInfo
{
public delegate string msgOut(string str);
public msgOut ShowMsg;
}
public static string ShowHTML(string str)
{
return string.Format("<B>{0}</B>", str);
}
public static string ShowTXT(string str)
{
return str;
}
#endregion
static void Main(string[] args)
{
for (int i = 0; i < 10; i++)
Console.WriteLine(numlist(i));
InsertRandomArr();
ShowMsgInfo sm = new ShowMsgInfo();
sm.ShowMsg = new ShowMsgInfo.msgOut(ShowHTML);
Console.WriteLine(sm.ShowMsg("Test"));
sm.ShowMsg = new ShowMsgInfo.msgOut(ShowTXT);
Console.WriteLine(sm.ShowMsg("Test2"));
Console.Read();
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace TestFuns
{
class Program
{
Functions#region Functions
/**//// <summary>
/// 数列
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
private static int numlist(int n){
if (n < 2)
return 1;
else
return numlist(n - 1) + numlist(n-2);
}
/**//// <summary>
/// 显示1-50随机数,各不相同
/// </summary>
private static void InsertRandomArr() {
int tmpNum=0;
ArrayList newarr = new ArrayList();
Random rd = new Random();
while (newarr.Count < 50) {
tmpNum = rd.Next(0, 51);
if (!newarr.Contains(tmpNum))
newarr.Add(tmpNum);
}
for (int i = 49; i > 0; i--) {
Console.Write(newarr[i].ToString()+" ");
}
}
#endregion
DelegateDemo#region DelegateDemo
public class ShowMsgInfo
{
public delegate string msgOut(string str);
public msgOut ShowMsg;
}
public static string ShowHTML(string str)
{
return string.Format("<B>{0}</B>", str);
}
public static string ShowTXT(string str)
{
return str;
}
#endregion
static void Main(string[] args)
{
for (int i = 0; i < 10; i++)
Console.WriteLine(numlist(i));
InsertRandomArr();
ShowMsgInfo sm = new ShowMsgInfo();
sm.ShowMsg = new ShowMsgInfo.msgOut(ShowHTML);
Console.WriteLine(sm.ShowMsg("Test"));
sm.ShowMsg = new ShowMsgInfo.msgOut(ShowTXT);
Console.WriteLine(sm.ShowMsg("Test2"));
Console.Read();
}
}
}
转载于:https://www.cnblogs.com/netwenchao/archive/2009/11/13/1602721.html