zoukankan
html css js c++ java
C#新特性
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
LocalApp.ConsoleApp
{
class
Program
{
delegate
void
LambdaHandler();
static
void
Main(
string
[] args)
{
//
Func 封装一个具有 1 - 4 个参数并返回 TResult 参数指定的类型值的方法。
Func
<
int
,
string
>
func
=
delegate
(
int
i)
{
return
Convert.ToString(i
*
i); }
;
Console.WriteLine(func(
3
));
/**/
/*
****************************************
*/
//
lambda 表达式,i 参数
Func
<
int
,
string
>
func2
=
i
=>
Convert.ToString(i
*
i);
Console.WriteLine(func2(
4
));
/**/
/*
****************************************
*/
Func
<
string
,
string
>
func3
=
a
=>
a.ToUpper();
string
[] array
=
{
"
hebei
"
,
"
hubei
"
,
"
beijing
"
,
"
12
"
}
;
IEnumerable
<
string
>
_array
=
array.Where
<
string
>
(b
=>
b.EndsWith(
"
i
"
));
//
array.Select(func3);
foreach
(
string
i
in
_array)
Console.WriteLine(i);
/**/
/*
****************************************
*/
Func
<
string
,
string
,
string
,
string
,
string
>
__func
=
(a, b, c, d)
=>
{
return
a
+
"
_
"
+
b
+
"
_
"
+
c
+
"
_
"
+
d; }
;
Console.WriteLine(__func(
"
h
"
,
"
e
"
,
"
l
"
,
"
lo
"
));
/**/
/*
****************************************
*/
Func
<
string
>
__func2
=
()
=>
"
123456
"
;
Console.WriteLine(__func2());
/**/
/*
****************************************
*/
LambdaHandler lam
=
()
=>
Console.WriteLine(
"
1111111111
"
);
lam
+=
()
=>
Console.WriteLine(
"
22222222222
"
);
lam();
/**/
/*
****************************************
*/
//
扩展方法
string
extTest
=
"
hello world
"
;
Console.WriteLine(extTest.WordCount());
foreach
(
string
i
in
extTest.WordSplit())
{
Console.WriteLine(i);
}
/**/
/*
****************************************
*/
Console.ReadKey(
true
);
}
}
/**/
///
<summary>
///
扩展方法
///
</summary>
public
static
class
Extensions
{
public
static
int
WordCount(
this
String str)
{
return
str.Split(
new
char
[]
{
'
'
,
'
.
'
,
'
?
'
}
, StringSplitOptions.RemoveEmptyEntries).Length;
}
public
static
string
[] WordSplit(
this
String str)
{
return
str.Split(
new
char
[]
{
'
'
,
'
.
'
,
'
?
'
}
, StringSplitOptions.None);
}
}
}
查看全文
相关阅读:
浅谈移动通信和无线通信
jdk8处理时间
Mysql查询报错:Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='
linux系统执行mysql脚本:Can't connect to local MySQL server through socket '/tmp/mysql.sock'
org.springframework.boot.web.server.WebServerException: Unable to create tempDir. java.io.tmpdir is set to C:UsersADMINI~1AppDataLocalTemp2
java实现每个单词首字母大写
常用Java技术社区
Hibernate处理事务并发问题
Hibernate的检索策略
Java对象在Hibernate持久化层的状态
原文地址:https://www.cnblogs.com/yiki/p/1378446.html
最新文章
ux.form.field.Password 密码与非密码状态切换
Ext-JS-Classic-Demo 面向pc端示例
ux.form.field.GridDate 支持快速选择日期的日期控件
Ext Js 6+ 如何引入dashboard模版
sencha cmd 更新日志
Ext JS 6 入门学习资料大全(2018-03-07)
ext 文档下载地址
ux.form.field.KindEditor 所见所得编辑器
ux.plup.File plupload 集成 ux.plup.FileLis 批量上传预览
ux.plugin.ConTpl 模版元素监听扩展
热门文章
ux.form.field.Verify 验证码控件
np.pad()详解
plt.rcParams()详解
plt.axis()用法详解
np.where()详解
np.array()和np.asarray()的区别
Pycharm新文件开头自动编写
enumerate()函数的用法
import sklearn的错误
Jupyter Notebook的安装与使用
Copyright © 2011-2022 走看看