没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
原创|行业资讯|编辑:郑恭琳|2015-08-31 10:49:24.000|阅读 496 次
概述:有关C#中15大被隐藏的顶级功能的第一个帖子是出现在Automate The Planet上。下面列出程序员在C#编程生涯中最喜欢的被隐藏的C#功能,包括完整的解释和代码示例。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
我不确定这些能不能被当作C#中隐藏的功能,因为它们没有被公开,因此应该谨慎使用。没有一个关于原因的文档,也许是因为没有经过充分的测试。然而,它们由Visual Studio编辑器着色,并且识别为官方关键字。
你可以通过使用__makeref关键字创建变量的类型引用。由类型引用表示的变量的原始类型可以使用__reftype关键字提取。最后,该值可以从使用__refvalue关键字从TypedReference获得。__arglist与关键字params具有相似的行为-可以访问参数列表。
int i = 21; TypedReference tr = __makeref(i); Type t = __reftype(tr); Console.WriteLine(t.ToString()); int rv = __refvalue( tr,int); Console.WriteLine(rv); ArglistTest.DisplayNumbersOnConsole(__arglist(1, 2, 3, 5, 6));
要使用__arglist,你需要ArglistTest类。
public static class ArglistTest { public static void DisplayNumbersOnConsole(__arglist) { ArgIterator ai = new ArgIterator(__arglist); while (ai.GetRemainingCount() > 0) { TypedReference tr = ai.GetNextArg(); Console.WriteLine(TypedReference.ToObject(tr)); } } }
从第一个可选参数开始备注ArgIterator对象列举的参数列表,这是专门为了与C/ C ++编程语言的使用提供的。
相关文档:http://www.nullskull.com/articles/20030114.asp 和http://community.bartdesmet.net/blogs/bart/archive/2006/09/28/4473.aspx
获取此环境中定义的换行符的字符串。
Console.WriteLine("NewLine: {0} first line{0} second line{0} third line", Environment.NewLine);
官方文档:https://msdn.microsoft.com/en-us/library/system.environment.newline(v=vs.110).aspx
表示在代码中特定点捕获的异常。你可以使用ExceptionDispatchInfo.Throw方法,可以在System.Runtime.ExceptionServices命名空间中找到。这种方法可用于引发异常和保留原始堆栈跟踪。
ExceptionDispatchInfo possibleException = null; try { int.Parse("a"); } catch (FormatException ex) { possibleException = ExceptionDispatchInfo.Capture(ex); } if (possibleException != null) { possibleException.Throw(); }
捕获到的异常可以通过另一种方法再次被抛出,甚至在另一个线程抛出。
官方文档:https://msdn.microsoft.com/en-us/library/system.runtime.exceptionservices.exceptiondispatchinfo(v=vs.110).aspx
如果要退出程序而无需调用任何finally块或终结器那么使用FailFast。
string s = Console.ReadLine(); try { int i = int.Parse(s); if (i == 42) Environment.FailFast("Special number entered"); } finally { Console.WriteLine("Program complete."); }
如果i=42,那么finally模块则不被执行。
官方文档:https://msdn.microsoft.com/en-us/library/ms131100(v=vs.110).aspx
Debug.Assert-检查条件;如果条件为假,输出的消息并显示调用堆栈的消息框。
Debug.Assert(1 == 0, "The numbers are not equal! Oh my god!");
如果断言在调试模式失败,则显示包含指定的消息的警告,如下:
Debug.WriteIf–如果条件为真,写关于侦听器集中的跟踪监听器调试信息。
Debug.WriteLineIf(1 == 1, "This message is going to be displayed in the Debug output! =)");
Debug.Indent/Debug.Unindent–把当前entLevel加一。
Debug.WriteLine("What are ingredients to bake a cake?"); Debug.Indent(); Debug.WriteLine("1. 1 cup (2 sticks) butter, at room temperature."); Debug.WriteLine("2 cups sugar"); Debug.WriteLine("3 cups sifted self-rising flour"); Debug.WriteLine("4 eggs"); Debug.WriteLine("1 cup milk"); Debug.WriteLine("1 teaspoon pure vanilla extract"); Debug.Unindent(); Debug.WriteLine("End of list");
如果要显示在调试输出窗口的各组分,可以使用上面的代码。
官方文档:Debug.Assert, Debug.WriteIf, Debug.Indent/Debug.Unindent
我不确定是否可以把它归类到C#中被隐藏的功能,因为在TPL (Task Parallel Library)经常用到。然而,我把它放这儿是因为我非常喜欢在多线程应用程序中用到它。
Parallel.For-执行迭代可以并行的for循环。
int[] nums = Enumerable.Range(0, 1000000).ToArray(); long total = 0; // Use type parameter to make subtotal a long, not an int Parallel.For<long>(0, nums.Length, () => 0, (j, loop, subtotal) => { subtotal += nums[j]; return subtotal; }, (x) => Interlocked.Add(ref total, x) ); Console.WriteLine("The total is {0:N0}", total);
Interlocked.Add方法新增两个整数,并将第一个整数替换为它们的和。
Parallel.Foreach-执行foreach操作,其中迭代可以并行运行。
int[] nums = Enumerable.Range(0, 1000000).ToArray(); long total = 0; Parallel.ForEach<int, long>(nums, // source collection () => 0, // method to initialize the local variable (j, loop, subtotal) => // method invoked by the loop on each iteration { subtotal += j; //modify local variable return subtotal; // value to be passed to next iteration }, // Method to be executed when each partition has completed. // finalResult is the final value of subtotal for a particular partition. (finalResult) => Interlocked.Add(ref total, finalResult)); Console.WriteLine("The total from Parallel.ForEach is {0:N0}", total);
官方文档:Parallel.For 和 Parallel.Foreach
返回一个指示指定数字是否计算为负或正无穷大的值。
Console.WriteLine("IsInfinity(3.0 / 0) == {0}.", Double.IsInfinity(3.0 / 0) ? "true" : "false");
官方文档:https://msdn.microsoft.com/en-us/library/system.double.isinfinity(v=vs.110).aspx
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com
那么,BarTender 支持哪些数据库类型?又是如何助力企业实现数据驱动的智能打印?今天,我们来全面拆解!
企业级软件测试方案Parasoft SOAtest推出的AI助手采用代理式AI,自动生成API测试场景,使不同水准的测试团队都能轻松实现API测试自动化。此次更新后,测试人员可以借助自然语言指令,结合服务定义文件,高效生成API测试场景。除此之外,AI助手还利用AI代理生成测试数据,并针对数据循环对测试场景进行参数化。
Parasoft Virtualize通过环境可视化、实时监控和智能虚拟化三大核心能力,帮开发团队提前扫清环境障碍,让测试效率大幅提升,从此告别“测试五分钟,排查两小时”的尴尬。
很多客户非常关心MES系统的价格问题。这里我们大概聊一下系统的大概价格是怎么定下来的。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@evget.com
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
慧都科技 版权所有 Copyright 2003-
2025 渝ICP备12000582号-13 渝公网安备
50010702500608号