publicinterfaceIPort<T>{TGo(T t);}publicclassperson<T>:MonoBehaviour,IPort<person<T>>{publicvirtualperson<T>Go(person<T> t){
Debug.Log("10");returnnull;}}publicclassstudent:person<student>{publicoverrideperson<student>Go(person<student> s){
Debug.Log("20");returnnull;}}publicclassteacher:person<teacher>{}publicclassTest:MonoBehaviour{voidStart(){person<student> s =newperson<student>();person<teacher> t =newperson<teacher>();student student =newstudent();teacher teacher =newteacher();
s.Go(s);//10
t.Go(t);//10
student.Go(student);//20
student.Go(s);//20
teacher.Go(teacher);//10
teacher.Go(t);//10}
泛型方法
泛型方法实例
publicclassAccount{publicstring Name {get;}publicint Balance {get;}publicAccount(string name,int balance){
Name = name;
Balance = balance;}}publicstaticclassAlgori{publicstaticintAcc(IEnumerable<Account> source)//IEnumerable是List等的基类{int sun =0;foreach(Account a in source){
sun+=a.Balance;}return sun;}}publicclassTest:MonoBehaviour{publicList<Account> acc;voidStart(){int index = Algori.Acc(acc);}
带约束的泛型方法
publicinterfaceIAccount{string Name {get;}int Balance {get;}}publicclassAccount:IAccount{publicstring Name {get;}publicint Balance {get;}publicAccount(string name,int balance){
Name = name;
Balance = balance;}}publicstaticclassAlgori{publicstaticintAcc<TAccount>(IEnumerable<TAccount> source)whereTAccount:IAccount//IEnumerable是List等的基类{int sun =0;foreach(TAccount a in source){
sun+=a.Balance;}return sun;}}publicclassTest:MonoBehaviour{publicList<Account> acc;voidStart(){int index = Algori.Acc(acc);}
带委托的泛型方法
publicinterfaceIAccount{string Name {get;}int Balance {get;}}publicclassAccount:IAccount{publicstring Name {get;}publicint Balance {get;}publicAccount(string name,int balance){
Name = name;
Balance = balance;}}publicstaticclassAlgori{publicstaticT2Acc<T1,T2>(IEnumerable<T1> source,Func<T1,T2,T2> action)//第三个T2表示返回值类型,不加下方委托实现则会报错{T2 sun =default(T2);foreach(T1 a in source){
sun=action(a,sun);}return sun;}}publicclassTest:MonoBehaviour{publicList<Account> acc;voidStart(){int index = Algori.Acc<Account,int>(acc,(Account a,int i)=>{return a.Balance + i;});}
问题描述
postgresql数据库执行delete报错:attempted to delete invisible tuple,执行同样条件的select不报错
delete from lzltab1;
select count(*) from lzltab1;执行全表删除和全表查询的结果:
M# delete from lzltab1;
ERROR: 5500…
6.28
一、问题描述
ROS运行roscore命令后发现提示log文件(日志文件)大小超过1G,需要清理
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
WARNING: disk usage in log directory [/home/wht/.ros/log] is over 1GB.
Its recom…