This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
using System.IO; | |
using System.Drawing; | |
using System.Drawing.Drawing2D; | |
using System.Drawing.Imaging; | |
namespace WuJian.Common | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//在.Net中不但可以像C语言一样将函数作为参数传递,并且.Net提供了类型安全机制和更加强大的功能,如下提供了使用委托的完整代码示例: | |
//增加语言,只需扩展LoveChinese 函数即可! | |
using System; | |
namespace DelegateDemo | |
{ | |
//定义委托 | |
public delegate void LoveDelegate(string name); | |
public class LoveManager |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//使用泛型改造Compare类。 | |
//这段代码在优雅度上完胜非泛型,并且可重用性大大提升,可以说它支持所有类型的比较,只要这个类型实现了IComparable接口,同时一劳永逸,不再需要在方法内部作任何扩展。 | |
public class Compare<T> where T : IComparable | |
{ | |
public T WhoIsBetter(T t1, T t2) | |
{ | |
if (t1.CompareTo(t2) > 0) | |
{ | |
return t1; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
message MyRequest { //客户端的请求 | |
required int32 version =1; //版本号 | |
required string name =2; //姓名 | |
optional string website =3[default="http://www.paotiao.com/"]; //个人网站 | |
optional bytes data =4; //附加数据 | |
} | |
message MyResponse { //服务端的响应 | |
required int32 version =1; //版本号 | |
required int32 result =2; //响应结果 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//颜色数组 | |
privatestring[] myColor =newstring[] | |
{ | |
"Fuchsia", | |
"Black", | |
"Gold", | |
"Blue", | |
"HotPink", | |
"Orange", | |
"Peru", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pipelineDemos | |
import ( | |
"fmt" | |
"sync" | |
"time" | |
) | |
// Multiple functions can read from the same channel until that channel is closed; this is called fan-out. | |
// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f, err := os.Open("a.txt") | |
defer f.Close() | |
if nil == err { | |
buff := bufio.NewReader(f) | |
for { | |
line, err := buff.ReadString('\n') | |
if err != nil || io.EOF == err{ | |
break | |
} | |
fmt.Println(line) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////文件:templates/layout.html | |
<html> | |
<head> | |
<title>{ { template "title" . } } </title> | |
</head> | |
<body | |
{ { template "content" . } } | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type testing_TBHelper interface { | |
Helper() | |
} | |
func Assert(tb testing.TB, condition bool, args ...interface{}) { | |
if x, ok := tb.(testing_TBHelper); ok { | |
x.Helper() // Go1.9+ | |
} | |
if !condition { | |
if msg := fmt.Sprint(args...); msg != "" { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
defer func() { for {} }() | |
} | |
func main() { | |
defer func() { select {} }() | |
} | |
func main() { | |
defer func() { <-make(chan bool) }() |