情节故事得有情节,不喜欢情节的朋友可看第1版代码,然后直接跳至“三.想要链式写法”

一.起缘

故事缘于一位朋友的一道题:

朋友四人玩LOL游戏。第一局,分别选择位置:中单,上单,ADC,辅助;第二局新加入的伙伴要选上单,四人可选位置变为:中单,打野,ADC,辅助;要求,第二局四人每人不得选择和第一局相同的位置,请问两局综合考虑有多少种位置选择方式?

对于像我这边不懂游戏的人来讲,看不懂。于是有了这个版本:

有4个人,4只椅子,第一局每人坐一只椅子,第二局去掉第2只椅子,增加第5只椅子,每人坐一只椅子,而且每个人不能与第一局坐相同的椅子。问两局综合考虑,共有多少种可能的情况?

我一开始的想法是这样的,4个人就叫ABCD:第1局可能数是4*3*2*1=24,如果A第1局选了第2张椅,则A有4种可能,否则A有3种可能。对B来讲,如果A选了B第一局的椅,则B有3种可能,否则B有2种可能(排队自己第一局和A第二局已选)……想到这里我就晕了,情况越分越多。

二.原始的for嵌套

本来是一道数学题,应该由知识算出来有多少种,但我突然有个想法,不如用计算机穷举出出来。一来可以为各种猜测提供一个正确的答案,二来或许可以从答案反推出(数学上的)计算方法。然后就写了第1版:

static Seat data = new Seat();
public static void Run()
{
for (int a = ; a < ; a++)
{
if (data.IsSelected(, a)) //第1局编号0。如果已经被人坐了。
continue;
data.Selected(, a, "A"); //第1局编号0。A坐a椅。
for (int b = ; b < ; b++)
{
if (data.IsSelected(, b))
continue;
data.Selected(, b, "B");
for (int c = ; c < ; c++)
{
if (data.IsSelected(, c))
continue;
data.Selected(, c, "C");
for (int d = ; d < ; d++)
{
if (data.IsSelected(, d))
continue;
data.Selected(, d, "D");
for (int a2 = ; a2 < ; a2++)
{
if (a2 == )
continue;
if (data.IsSelected(, a2)) //第2局编号1
continue;
if (data.IsSelected(, a2, "A")) //如果第1局A坐了a2椅
continue;
data.Selected(, a2, "A");
for (int b2 = ; b2 < ; b2++)
{
if (b2 == )
continue;
if (data.IsSelected(, b2))
continue;
if (data.IsSelected(, b2, "B"))
continue;
data.Selected(, b2, "B");
for (int c2 = ; c2 < ; c2++)
{
if (c2 == )
continue;
if (data.IsSelected(, c2))
continue;
if (data.IsSelected(, c2, "C"))
continue;
data.Selected(, c2, "C");
for (int d2 = ; d2 < ; d2++)
{
if (d2 == )
continue;
if (data.IsSelected(, d2))
continue;
if (data.IsSelected(, d2, "D"))
continue;
data.Selected(, d2, "D"); data.Count++; //可能的情况数加1
Console.WriteLine("{0,5} {1}", data.Count, data.Current); data.UnSelected(, d2);
}
data.UnSelected(, c2);
}
data.UnSelected(, b2);
}
data.UnSelected(, a2);
}
data.UnSelected(, d);
}
data.UnSelected(, c);
}
data.UnSelected(, b);
}
data.UnSelected(, a); //A起身(释放坐椅)
}
}

部分运行结果:

说明:
1.ABCD是人名
2.“.”代表没有人
3.位置是是座位
4.-左边是第1局,右边是第2局
5.数字是序号

1 A B C D .-B . A C D
2 A B C D .-C . A B D
3 A B C D .-D . A B C
4 A B C D .-D . A C B
5 A B C D .-B . D A C
6 A B C D .-C . B A D
7 A B C D .-D . B A C
8 A B C D .-C . D A B
9 A B C D .-B . D C A
10 A B C D .-D . B C A
11 A B C D .-C . D B A
12 A B D C .-B . A D C
...
262 D C B A .-B . C D A
263 D C B A .-B . D C A
264 D C B A .-C . D B A

算出来是264种。从答案上来看是每11种是一组,一组中第1局的坐法是相同的,也就是说对于第一局的每一种情况,第2局都是有11种不同的可能。而第一局的可能性是24,所以答案是24*11=264。而第2局为什么是11种可能,后面再说。

三.想要链式写法

主题来了,像刚才的第1版的写法太死板太麻烦了。
如果能像这样写代码就爽了:

obj.Try("A").Try("B").Try("C").Try("D").Try2("A").Try2("B").Try2("C").Try2("D").Write();

而这样的代码通常的逻辑是执行Try("A")方法,然后执行Try("A")它return的对象的Try("B")方法……,即是Try("B")方法只被执行1次,而我希望的是Try("B")方法被Try("A")内部循环调用n次,Try("C")方法又被Try("B")方法调用m次。想想第1版的for套for不难明白为什么要追求这样的效果。如果Try("A")执行完了,再去执行Try("B"),那么Try("B")肯定不会被调用多次,所以得延迟Try("A")的执行,同理也延迟所有Try和Try2的执行。由于lambda表达天生有延迟计算的特性,于是很快写出了第2版:

public static void Run2()
{
Try("A",
() => Try("B",
() => Try("C",
() => Try("D",
() => Try2("A",
() => Try2("B",
() => Try2("C",
() => Try2("D",
null
)
)
)
)
)
)
)
);
}
public static void Try(string name, Action action) //第1局
{
for (int i = ; i < ; i++)
{
if (data.IsSelected(, i))
continue;
data.Selected(, i, name);
if (action == null)
{
Console.WriteLine(data.Current);
}
else
{
action();
}
data.UnSelected(, i);
}
}
public static void Try2(string name, Action action) //第2局
{
for (int i = ; i < ; i++)
{
if (i == )
continue;
if (data.IsSelected(, i))
continue;
if (data.IsSelected(, i, name))
continue;
data.Selected(, i, name);
if (action == null)
{
data.Count++;
Console.WriteLine("{0,5} {1}", data.Count, data.Current);
}
else
{
action();
}
data.UnSelected(, i);
}
}

结构更合理,逻辑更清晰,但是一堆lambda嵌套,太丑了,也不是我要的效果,我要的是类似这样的:

obj.Try("A").Try("B").Try("C").Try("D").Try2("A").Try2("B").Try2("C").Try2("D").Write();

四.继续向目标逼近。
由于要延迟,所以必须先把要被调用的方法的引用“告诉”上一级,当上一级执行for的时候,就能调用下一级的方法。于是我想到了一个“回调链”

所以,执行链式方法是在构造回调链,最后的方法再通过调用链头(Head)的某个方法启动真正要执行的整个逻辑。
延迟计算是从Linq借鉴和学习来的,构造Linq的过程并没有执行,等到了执行ToList, First等方法时才真正去执行。
我想构造回调链每一步都是一个固定的方法,这里随便起用了T这个极短名称,而每一步后期计算时要执行的方法可灵活指定。于是有了第3版:

static Seat data = new Seat();      //借用Seat保存数据
public Seat2(string name, Seat2 parent, Action<Seat2> method)
{
this.Name = name;
this.Parent = parent;
if (parent != null)
parent.Child = this;
this.Method = method;
}
public static void Run()
{
new Seat2("A", null, me => me.Try())
.T("B", me => me.Try())
.T("C", me => me.Try())
.T("D", me => me.Try())
.T("A", me => me.Try2())
.T("B", me => me.Try2())
.T("C", me => me.Try2())
.T("D", me => me.Try2())
.P().Start();
}
public Seat2 T(string name, Action<Seat2> method)
{
return new Seat2(name, this, method);
}
public void Try()
{
for (int i = ; i < ; i++)
{
if (data.IsSelected(, i))
continue;
data.Selected(, i, this.Name);
if (this.Child != null)
{
this.Child.Method(this.Child);
}
data.UnSelected(, i);
}
}
public void Try2()
{
for (int i = ; i < ; i++)
{
if (i == )
continue;
if (data.IsSelected(, i))
continue;
if (data.IsSelected(, i, this.Name))
continue;
data.Selected(, i, this.Name);
if (this.Child != null)
{
this.Child.Method(this.Child);
}
data.UnSelected(, i);
}
}

五.解耦
这种调用方式,是满意了。但是运算框架与具体的算法耦合在一起,如果能把运算框架提取出来,以后写具体的算法也方便许多。于是经过苦逼的提取,测试,踩坑,最终出现了第4版:

 //运算框架
class ComputeLink<T> where T : ISeat3
{
ComputeLink<T> Parent { get; set; } //父节点,即上一级节点
ComputeLink<T> Child { get; set; } //子节点,即下一级节点
T Obj { get; set; } //当前节点对应的算法对象,可以看作业务对象
public ComputeLink(T obj, ComputeLink<T> parent, Action<T> method)
{
if (obj == null)
throw new ArgumentNullException("obj");
this.Obj = obj;
this.Obj.Method = x => method((T)x);
if (parent != null)
{
this.Parent = parent;
parent.Child = this;
parent.Obj.Child = this.Obj;
}
}
public static ComputeLink<T> New(T obj, Action<T> method)
{
return new ComputeLink<T>(obj, null, method);
} public ComputeLink<T> Do(T obj, Action<T> method)
{
return new ComputeLink<T>(obj, this, method);
}
public ComputeLink<T> Head //链表的头
{
get
{
if (null != this.Parent)
return this.Parent.Head;
return this;
}
}
public void Action() //启动(延迟的)整个计算
{
var head = this.Head;
head.Obj.Method(head.Obj);
}
}
interface ISeat3
{
ISeat3 Child { get; set; }
Action<ISeat3> Method { get; set; }
}

p.s.为什么第4版是ISeat3而不是ISeat4呢,因为我本不把第1版当作1个版本,因为太原始了,出现第2版后,我就把第1版给删除了。为了写这篇文章才重新去写第1版。于是原本我当作第3版的ISeat3自然地排到了第4版。

具体的"算法"就很简单了:

class Seat3 : ISeat3
{
static Seat data = new Seat();
string Name { get; set; }
public Seat3(string name)
{
this.Name = name;
}
/// <summary>
/// 解耦的版本
/// </summary>
public static void Run()
{
var sql = ComputeLink<Seat3>
.New(new Seat3("A"), m => m.Try())
.Do(new Seat3("B"), m => m.Try())
.Do(new Seat3("C"), m => m.Try())
.Do(new Seat3("D"), m => m.Try())
.Do(new Seat3("A"), m => m.Try2())
.Do(new Seat3("B"), m => m.Try2())
.Do(new Seat3("C"), m => m.Try2())
.Do(new Seat3("D"), m => m.Try2())
.Do(new Seat3(""), m => m.Print());
sql.Action();
}
public Action<ISeat3> Method { get; set; }
public ISeat3 Child { get; set; }
public void Try()
{
for (int i = ; i < ; i++)
{
if (data.IsSelected(, i))
continue;
data.Selected(, i, this.Name);
if (this.Child != null)
{
this.Child.Method(this.Child);
}
data.UnSelected(, i);
}
}
public void Try2()
{
for (int i = ; i < ; i++)
{
if (i == )
continue;
if (data.IsSelected(, i))
continue;
if (data.IsSelected(, i, this.Name))
continue;
data.Selected(, i, this.Name);
if (this.Child != null)
{
this.Child.Method(this.Child);
}
data.UnSelected(, i);
}
}
public void Print()
{
data.Count++;
Console.WriteLine("{0,5} {1}", data.Count, data.Current);
}
}

Seat3写起来简单,(Run方法内部)看起来舒服。通过链式写法达到嵌套循环的效果。对,这就是我要的!
它很像linq,所以我直接给变量命名为sql。

  • 对于Try和Try2来讲,要调用的方法最好从参数传来,但是这样就会增加Run方法中New和Do的参数复杂性,破坏了美感,所以经过权衡,Child和Method通过属性传入。这个我也不确定这样做好不好,请各位大侠指点。
  • 还有一个细节,就是ComputeLink构造方法中的(行号12的)代码 this.Obj.Method = x => method((T)x); 。我原来是这样写的 this.Obj.Method = method; 编译不通过,原因是不能把 Action<ISeat3> 转化为 Action<T> ,虽然T一定实现了ISeat3,强制转化也不行,想起以前看过的一篇文章里面提到希望C#以后的版本能拥有的一特性叫“协变”,很可能指的就是这个。既然这个 Action<ISeat3> 不能转化为 Action<T> 但是ISeat3是可以强制转化为T的,所以我包了一层薄薄的壳,成了 this.Obj.Method = x => method((T)x); ,如果有更好的办法请告诉我。

六.第2局为什么是11种可能
回过头来解决为什么对于一个确定的第1局,第2局有11种可能。
不妨假设第1局的选择是A选1号椅,B选2号椅,C选3号椅,D选4号椅。
第2局分为两大类情况:
如果B选了第5号椅
则只有2种可能:
A B C D .-D . A C B
A B C D .-C . D A B
如果B选了不是第5号椅,
则ACD都有可能选第5号椅,有3种可能。B有3种选的可能(1,3,4号椅),B一旦确定,A和C也只有一种可能
所以11 = 2 + 3 * 3
七.结论
由一道数学题牵引出多层循环嵌套,最终通过封装达到了我要的链式调用的效果,我是很满意的。这也是我第一次设计延迟计算,感觉强烈。如果新的场景需要用到延迟计算我想有了这次经验写起来会顺手许多。如果是需要多层for的算法题都可以比较方便的实现了。

你都看到这里了,为我点个赞吧,能说一下看法就更好了。

完整代码:

 using System;
using System.Linq;
using System.Diagnostics; namespace ConsoleApplication1
{
class Seat
{
static Seat data = new Seat();
public static void Run()
{
//Seat2.Run();
//return;
for (int a = ; a < ; a++)
{
if (data.IsSelected(, a)) //第1局编号0。如果已经被人坐了。
continue;
data.Selected(, a, "A"); //第1局编号0。A坐a椅。
for (int b = ; b < ; b++)
{
if (data.IsSelected(, b))
continue;
data.Selected(, b, "B");
for (int c = ; c < ; c++)
{
if (data.IsSelected(, c))
continue;
data.Selected(, c, "C");
for (int d = ; d < ; d++)
{
if (data.IsSelected(, d))
continue;
data.Selected(, d, "D");
for (int a2 = ; a2 < ; a2++)
{
if (a2 == )
continue;
if (data.IsSelected(, a2)) //第2局编号1
continue;
if (data.IsSelected(, a2, "A")) //如果第1局A坐了a2椅
continue;
data.Selected(, a2, "A");
for (int b2 = ; b2 < ; b2++)
{
if (b2 == )
continue;
if (data.IsSelected(, b2))
continue;
if (data.IsSelected(, b2, "B"))
continue;
data.Selected(, b2, "B");
for (int c2 = ; c2 < ; c2++)
{
if (c2 == )
continue;
if (data.IsSelected(, c2))
continue;
if (data.IsSelected(, c2, "C"))
continue;
data.Selected(, c2, "C");
for (int d2 = ; d2 < ; d2++)
{
if (d2 == )
continue;
if (data.IsSelected(, d2))
continue;
if (data.IsSelected(, d2, "D"))
continue;
data.Selected(, d2, "D"); data.Count++; //可能的情况数加1
Console.WriteLine("{0,5} {1}", data.Count, data.Current); data.UnSelected(, d2);
}
data.UnSelected(, c2);
}
data.UnSelected(, b2);
}
data.UnSelected(, a2);
}
data.UnSelected(, d);
}
data.UnSelected(, c);
}
data.UnSelected(, b);
}
data.UnSelected(, a); //A起身(释放坐椅)
}
}
public static void Run2()
{
Try("A",
() => Try("B",
() => Try("C",
() => Try("D",
() => Try2("A",
() => Try2("B",
() => Try2("C",
() => Try2("D",
null
)
)
)
)
)
)
)
);
}
public static void Try(string name, Action action)
{
for (int i = ; i < ; i++)
{
if (data.IsSelected(, i))
continue;
data.Selected(, i, name);
if (action == null)
{
Console.WriteLine(data.Current);
}
else
{
action();
}
data.UnSelected(, i);
}
} public static void Try2(string name, Action action)
{
for (int i = ; i < ; i++)
{
if (i == )
continue;
if (data.IsSelected(, i))
continue;
if (data.IsSelected(, i, name))
continue;
data.Selected(, i, name);
if (action == null)
{
data.Count++;
Console.WriteLine("{0,5} {1}", data.Count, data.Current);
}
else
{
action();
}
data.UnSelected(, i);
}
}
public Seat()
{
seats[, ] = ".";
seats[, ] = ".";
}
private string[,] seats = new string[, ];
public void UnSelected(int game, int i)
{
Debug.Assert(game == && i != || game == && i != );
Debug.Assert(seats[game, i] != null);
seats[game, i] = null;
}
public void Selected(int game, int i, string name)
{
Debug.Assert(game == && i != || game == && i != );
Debug.Assert(seats[game, i] == null);
seats[game, i] = name;
}
public bool IsSelected(int game, int a)
{
return seats[game, a] != null && seats[game, a] != ".";
}
public bool IsSelected(int game, int a, string name)
{
return seats[game, a] == name;
}
public string Current
{
get
{
return string.Format("{0} {1} {2} {3} {4}-{5} {6} {7} {8} {9}",
seats[, ], seats[, ], seats[, ], seats[, ], seats[, ],
seats[, ], seats[, ], seats[, ], seats[, ], seats[, ]);
}
} public int Count { get; set; }
} class Seat2
{
static Seat data = new Seat(); //借用Seat保存法的数据
Seat2 Parent { get; set; }
Seat2 Child { get; set; }
string Name { get; set; }
Action<Seat2> Method { get; set; }
public Seat2(string name, Seat2 parent, Action<Seat2> method)
{
this.Name = name;
this.Parent = parent;
if (parent != null)
parent.Child = this;
this.Method = method;
}
/// <summary>
/// 耦合的版本
/// </summary>
public static void Run()
{
new Seat2("A", null, me => me.Try())
.T("B", me => me.Try())
.T("C", me => me.Try())
.T("D", me => me.Try())
.T("A", me => me.Try2())
.T("B", me => me.Try2())
.T("C", me => me.Try2())
.T("D", me => me.Try2())
.P().Start();
}
public Seat2 T(string name, Action<Seat2> method)
{
return new Seat2(name, this, method);
}
public Seat2 P()
{
return new Seat2("Print", this, me => me.Print());
}
public void Start()
{
var head = this.Head;
head.Method(head);
}
public Seat2 Head
{
get
{
if (null != this.Parent)
return this.Parent.Head;
return this;
}
}
public void Try()
{
for (int i = ; i < ; i++)
{
if (data.IsSelected(, i))
continue;
data.Selected(, i, this.Name);
if (this.Child != null)
{
this.Child.Method(this.Child);
}
data.UnSelected(, i);
}
}
public void Try2()
{
for (int i = ; i < ; i++)
{
if (i == )
continue;
if (data.IsSelected(, i))
continue;
if (data.IsSelected(, i, this.Name))
continue;
data.Selected(, i, this.Name);
if (this.Child != null)
{
this.Child.Method(this.Child);
}
data.UnSelected(, i);
}
}
public void Print()
{
data.Count++;
Console.WriteLine("{0,5} {1}", data.Count, data.Current);
} public override string ToString()
{
return this.Name.ToString();
}
} class ComputeLink<T> where T : ISeat3
{
ComputeLink<T> Parent { get; set; } //父节点,即上一级节点
ComputeLink<T> Child { get; set; } //子节点,即下一级节点
T Obj { get; set; } //当前节点对应的算法对象,可以看作业务对象
public ComputeLink(T obj, ComputeLink<T> parent, Action<T> method)
{
if (obj == null)
throw new ArgumentNullException("obj");
this.Obj = obj;
this.Obj.Method = x => method((T)x);
if (parent != null)
{
this.Parent = parent;
parent.Child = this;
parent.Obj.Child = this.Obj;
}
}
public static ComputeLink<T> New(T obj, Action<T> method)
{
return new ComputeLink<T>(obj, null, method);
} public ComputeLink<T> Do(T obj, Action<T> method)
{
return new ComputeLink<T>(obj, this, method);
}
public ComputeLink<T> Head //链表的头
{
get
{
if (null != this.Parent)
return this.Parent.Head;
return this;
}
}
public void Action() //启动(延迟的)整个计算
{
var head = this.Head;
head.Obj.Method(head.Obj);
}
}
interface ISeat3
{
ISeat3 Child { get; set; }
Action<ISeat3> Method { get; set; }
}
class Seat3 : ISeat3
{
static Seat data = new Seat();
string Name { get; set; }
public Seat3(string name)
{
this.Name = name;
}
/// <summary>
/// 解耦的版本
/// </summary>
public static void Run()
{
var sql = ComputeLink<Seat3>
.New(new Seat3("A"), m => m.Try())
.Do(new Seat3("B"), m => m.Try())
.Do(new Seat3("C"), m => m.Try())
.Do(new Seat3("D"), m => m.Try())
.Do(new Seat3("A"), m => m.Try2())
.Do(new Seat3("B"), m => m.Try2())
.Do(new Seat3("C"), m => m.Try2())
.Do(new Seat3("D"), m => m.Try2())
.Do(new Seat3(""), m => m.Print());
sql.Action();
}
public Action<ISeat3> Method { get; set; }
public ISeat3 Child { get; set; }
public void Try()
{
for (int i = ; i < ; i++)
{
if (data.IsSelected(, i))
continue;
data.Selected(, i, this.Name);
if (this.Child != null)
{
this.Child.Method(this.Child);
}
data.UnSelected(, i);
}
}
public void Try2()
{
for (int i = ; i < ; i++)
{
if (i == )
continue;
if (data.IsSelected(, i))
continue;
if (data.IsSelected(, i, this.Name))
continue;
data.Selected(, i, this.Name);
if (this.Child != null)
{
this.Child.Method(this.Child);
}
data.UnSelected(, i);
}
}
public void Print()
{
data.Count++;
Console.WriteLine("{0,5} {1}", data.Count, data.Current);
} public override string ToString()
{
return this.Name.ToString();
}
}
}

C#用链式方法表达循环嵌套的更多相关文章

  1. C#用链式方法

    C#用链式方法表达循环嵌套   情节故事得有情节,不喜欢情节的朋友可看第1版代码,然后直接跳至“三.想要链式写法” 一.起缘 故事缘于一位朋友的一道题: 朋友四人玩LOL游戏.第一局,分别选择位置:中 ...

  2. C#中扩展StringBuilder支持链式方法

    本篇体验扩展StringBuilder使之支持链式方法. 这里有一个根据键值集合生成select元素的方法. private static string BuilderSelectBox(IDicti ...

  3. Java链式方法 连贯接口(fluent interface)

    有两种情况可运用链式方法: 第一种  除最后一个方法外,每个方法都返回一个对象 object2 = object1.method1(); object3 = object2.method2(); ob ...

  4. 简谈 JavaScript、Java 中链式方法调用大致实现原理

    相信,在 JavaScript .C# 中都见过不少链式方法调用,那么,其中实现该类链式调用原理,大家有没有仔细思考过?其中 JavaScript 类库:jQuery 中就存在大量例子,而在 C# 中 ...

  5. Java链式方法

    http://blog.csdn.net/lemon_shenzhen/article/details/6358537 有两种情况可运用链式方法: 第一种  除最后一个方法外,每个方法都返回一个对象 ...

  6. C ~ 链式队列与循环队列

          此处的链式与循环队列可以应用于BFS和树的层序遍历.下面是对其结构和基本操作的程序描述. 1.循环队列 解决循环队列的队空和队满的方法: [1].增加一个参数count,用来记录数组中当前 ...

  7. day16模块,导入模板完成的三件事,起别名,模块的分类,模块的加载顺序,环境变量,from...import语法导入,from...import *,链式导入,循环导入

    复习 ''' 1.生成器中的send方法 -- 给当前停止的yield发生信息 -- 内部调用__next__()取到下一个yield的返回值 2.递归:函数的(直接,间接)自调用 -- 回溯 与 递 ...

  8. 基于mybatis-generator代码生成工具改(链式方法实体版)

    概述 一直以来使用原生mybatis-generator的我发现有一个地方很不方便,即它生成的实体类的set方法返回值是void,而目前比较流行的则是链式set的写法,即set方法返回值不再是void ...

  9. 像jQuery那样,采用链式方法,封装一个方法:CSS()

    主要思路就是:返回this对象,将所获取的操作元素放入一个数组中.在原型中添加拓展方法 <html> <head> <title></title> &l ...

随机推荐

  1. Entity Framework 6 Recipes 2nd Edition(10-10)译 - > 为TPH继承的插入、更新、删除操作映射到存储过程

    10-10. 为TPH继承的插入.更新.删除操作映射到存储过程 问题 TPH继承模型,想把它的插入.修改.删除操作映射到存储过程 Solution 假设数据库有一个描述不同种类的产品表(Product ...

  2. 【原】得心应手小工具开发——IE代理快速切换工具

    一.引入 因为公司里上外网要经常换IE代理地址,每次切换地址都要进到Internet Options里去设置一番,经常切换的话很是麻烦,由于用了点时间作个小工具来方便自己. 二.实现思路 其实思路很简 ...

  3. dhcp协议交互报文

    DHCP共有八种报文,分别为DHCP Discover.DHCP Offer.DHCP Request.DHCP ACK.DHCP NAK.DHCP Release.DHCP Decline.DHCP ...

  4. WCF学习之旅—WCF服务部署到IIS7.5(九)

    上接   WCF学习之旅—WCF寄宿前的准备(八) 四.WCF服务部署到IIS7.5 我们把WCF寄宿在IIS之上,在IIS中宿主一个服务的主要优点是在发生客户端请求时宿主进程会被自动启动,并且你可以 ...

  5. eclipse 突然 一直在loading descriptor for XXX (XXX为工程名)Cancel Requested

    问题: eclipse 启动后,啥也不干,就一直在loading descriptor for XXX (XXX为工程名),,其他什么操作都不能操作. 如下图所示,保存文件也无法保存.  这个怎么办? ...

  6. 关于安卓6.0权限申请 PermissionDog

    最近在一家公司实习,项目中需要用到适配安卓6.0以上的系统,我本来是想用其他人已经写好的权限申请框架来实现的,但是发现跟我的需求有点小区别,所以就自己写了一个 这个权限申请的帮助类很小,只有一个jav ...

  7. 如果你也会C#,那不妨了解下F#(4):了解函数及常用函数

    函数式编程其实就是按照数学上的函数运算思想来实现计算机上的运算.虽然我们不需要深入了解数学函数的知识,但应该清楚函数式编程的基础是来自于数学. 例如数学函数\(f(x) = x^2+x\),并没有指定 ...

  8. 学习javascript数据结构(二)——链表

    前言 人生总是直向前行走,从不留下什么. 原文地址:学习javascript数据结构(二)--链表 博主博客地址:Damonare的个人博客 正文 链表简介 上一篇博客-学习javascript数据结 ...

  9. angularjs和ajax的结合使用 (二)

    今天我们来继续丰富上次的例子.我们来搞些 稍微复杂点的应用. 首先我们来加一个全选 的功能. 上一篇的例子里我们看到 分页时载入的是我们通过linq 查询自定义列 然后构建的匿名类 .使用这种EF框架 ...

  10. .NET 同步与异步之封装成Task(五)

    本随笔续接:.NET 实现并行的几种方式(四) 前篇随笔已经介绍了几种可以实现并发的方式,其中异步方法.是最简便的方式.而 异步方式是基于 Task 和 async修饰符和await运算符实现的. 换 ...