十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
今天就跟大家聊聊有关C# 中switch和case如何使用,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
网站的建设创新互联公司专注网站定制,经验丰富,不做模板,主营网站定制开发.小程序定制开发,H5页面制作!给你焕然一新的设计体验!已为岗亭等企业提供专业服务。
public static class SwithCaseExtension
{
SwithCase#region SwithCase
public class SwithCase
, TOther> {
public SwithCase(TCase value, Action
action) {
Value = value;
Action = action;
}
public TCase Value { get; private set; }
public Action
Action { get; private set; } }
#endregion
Swith#region Swith
public static SwithCase
, TOther> Switch , TOther>
(this TCase t, Actionaction) where TCase : IEquatable {
return new SwithCase
, TOther>(t, action); }
public static SwithCase
, TOther> Switch , TCase, TOther>
(this TInput t, Func, TCase> selector, Action action)
where TCase : IEquatable{
return new SwithCase
, TOther>(selector(t), action); }
#endregion
Case#region Case
public static SwithCase
, TOther> Case , TOther>
(this SwithCase, TOther> sc, TCase option, TOther other)
where TCase : IEquatable{
return Case(sc, option, other, true);
}
public static SwithCase
, TOther> Case , TOther>
(this SwithCase, TOther> sc, TCase option, TOther other, bool bBreak)
where TCase : IEquatable{
return Case(sc, c=>c.Equals(option), other, bBreak);
}
public static SwithCase
, TOther> Case , TOther>
(this SwithCase, TOther> sc, Predicate predict, TOther other)
where TCase : IEquatable{
return Case(sc, predict, other, true);
}
public static SwithCase
, TOther> Case , TOther>
(this SwithCase, TOther> sc, Predicate predict,
TOther other, bool bBreak) where TCase : IEquatable{
if (sc == null) return null;
if (predict(sc.Value))
{
sc.Action(other);
return bBreak ? null : sc;
}
else return sc;
}
#endregion
Default#region Default
public static void Default
, TOther>
(this SwithCase, TOther> sc, TOther other) {
if (sc == null) return;
sc.Action(other);
}
#endregion
}
看完上述内容,你们对C# 中switch和case如何使用有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。