泛型到底是干嘛的?有什么好处?小例子

 
     
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Fanxing
{
class Program
{
public delegate bool del( int x);

static void Main( string [] args)
{
IList
< Int32 > i = new List < int > { 44 , 33 , 55 };

List
< Int32 > j = new List < int > { 5 , 2 , 3 };

// j.Add(9);
j.Sort( new Comparison < int > ( new hehe().Result));

j.AddRange(
new Int32[] { 11 , 22 , 33 }); // AddRange是指一个可以枚举的集合

j.Where((
int q) => { return q > 3 ; }); // 没搞清楚


int num = j.Find(( int p) => { return p == 3 ; });
// Console.WriteLine(num);

Console.WriteLine(
" List.Find方法(参数委托类型) " );
Console.WriteLine(j.Find(
delegate ( int x) { return x > 2 ; }));
Console.WriteLine(
" List.FindAll方法(参数委托类型) " );
Console.WriteLine((j.FindAll(
delegate ( int x) { return x > 2 ; }))[ 0 ]);
Console.WriteLine(
" List.Find方法(参数是另外定义的方法) " );
Console.WriteLine(j.Find(
new hehe().show));
Console.WriteLine(
" List.Find方法(参数是兰姆达表达式) " );
Console.WriteLine(j.Find((
int x) => { return x > 3 && x < 5 ; }));
Console.WriteLine((j.Where((
int x) => { return x > 3 && x < 8 ; }))); // 如果条件不止一个,该怎么写
// Console.WriteLine("{0},{1},{2},{3}", j[0], j[1], j[2], j[3]);
Type t = j.GetType();

List
< test > c = new List < test > ();
c.Add(
new tson());
c.Sort();

// Console.Write(c[0].GetType());
Console.ReadLine();
}
}
public class test
{
}

public class tson : test
{

}

public class hehe
{
public int Result( int x, int y)
{
if (x > y)
return 0 ;
else
return 1 ;
}

public bool Get( int x)
{
x
= 22 ;
return true ;
}

public bool show( int x)
{
if (x > 3 )
return true ;
else
return false ;
}
}
}
posted on 2011-02-15 21:44  人的本质是什么? 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/PirateCaptain/articles/1955580.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值