【c# – 如何在Windows中迭代无响应的程序?】教程文章相关的互联网学习教程文章

c# – 从最后一个叶子到根目录迭代TreeView节点的算法【代码】

将WinForms TreeView控件从最后一个叶子迭代到反向根的最佳算法是什么? C#解决方法:下面的代码将访问每个节点并完全遍历它,深度优先,直到它到达一个叶子.然后,当它展开堆栈时,将为每个节点调用DoSomethingWithNode. depth参数用于显示节点以相反的顺序返回.void ReverseTraverse(TreeNodeCollection nodes, int depth) {if (nodes == null) return;foreach (TreeNode child in nodes){ReverseTraverse(child.Nodes, depth+1);DoSo...

c# – 如何以最有效的方式迭代和删除hashset中的元素【代码】

好的,我想出了什么,但我想知道这是最有效的方式.我需要为ram内存问题做这件事.HashSet<string> hsLinks = new HashSet<string>(); List<string> lstSortList = new List<string>();// fill hashset with millions of recordswhile (true) {string srLastitem = "";foreach (var item in hsLinks){srLastitem = item;break;}lstSortList.Add(srLastitem);hsLinks.Remove(srLastitem);if (hsLinks.Count == 0)break; }c#.net 4.5.2 w...

c# – 简化用Java编写自定义迭代器【代码】

在Java中为自定义集合编写迭代器非常复杂,因为您不必编写提供一个元素的直接代码,而是必须编写状态机:public class CustomCollection<T> implements Iterable<T> {private T[] data;private int size;@Overridepublic Iterator<T> iterator(){return new Iterator<T>(){private int cursor = 0;@Overridepublic boolean hasNext(){return cursor < size;}@Overridepublic T next(){return data[cursor++];}@Overridepublic void r...

c# – RNGCryptoServiceProvider不会为相同的PWD,Salt,迭代组合生成相同的哈希值【代码】

Oki所以我想通过在.Net中添加随机盐来哈希我的密码.我用于此目的的内置类是RNGCryptoServiceProvider – 生成随机盐和Rfc2898DeriveBytes – 来散列实际密码. 但是当我将Rfc2898DeriveBytes的GetBytes()函数调用为passwordString,SaltBytes&的相同组合时.迭代计数结果不同.我粘贴我的代码以供参考public class PBKDF2Implementation{int minSaltSize = 32;int maxSaltSize = 64;public string CreateHash(string plainText , out...

c# – 使用EnvDte迭代类成员时跳过私有属性【代码】

我编写了这个帮助器方法来从类中获取属性,但它也获取了私有属性.我怎样才能获得公共财产?public IEnumerable<string> GetProperties(CodeClass @class) {return @class.Members.Cast<CodeElement>().Where(ce => ce.Kind == vsCMElement.vsCMElementProperty).Select(ce => ce.Name).ToList(); }更新:您可以在这里查看有关此技术http://andersmalmgren.com/2014/02/05/typed-javascript-contracts-using-t4-templates/的更深入的...

c# – 如何在select new MyObject中传递当前索引迭代【代码】

这是我的代码:infoGraphic.chartData = (from x in db.MyDataSourcegroup x by x.Data.Value.Year into gselect new MyObject{index = "", // here I need a string such as "index is:" + indexcounter = g.Count()});我需要select new中的当前索引迭代.我在哪里通过? 编辑 – 我目前的查询:var test = db.MyData.GroupBy(item => item.Data.Value.Year).Select((item, index ) => new ChartData(){index = ((double)(3 + inde...

c# – 如何迭代静态类中的所有静态公共Guid【代码】

参见英文答案 > How to get all static properties and its values of a class using reflection 1个给定是我的示例类:public static class MyConstantClass {public static readonly Guid Prop1 = new Guid("d0f6f396-b75e-4312-bb54-09fbb40cf51e");public static readonly Guid Prop2 = new Guid("398810e5-1ed2-468c-9f21-1af58dcecbbf"); }我到目前为止所尝试的内容:var props= typeof(...

c# – 匿名委托在本地stackalloc上的数据时不为每次迭代使用新的本地【代码】

在C#中使用匿名委托时,CLR将在堆上为已使用的变量生成本地副本(例如,当前作用域中的变量).对于当前作用域的每个声明变量,这样的local将被放到堆上. 您可以在此示例中看到此行为:class Program {static void Main(string[] args){for (int i = 0; i < 5; i++)ThreadPool.QueueUserWorkItem(delegate { execute(i); });Thread.Sleep(1000);Console.WriteLine();for (int i = 0; i < 5; i++){int j = i;ThreadPool.QueueUserWorkItem...

c# – 使用Silverlight 4中的ComAutomationFactory对Word文档字段进行迭代【代码】

更新:这是Silverlight 4测试版中确认的错误. http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=523052 我通过切换到完整的WPF应用程序并使用常规的旧Microsoft.Office.Interop.Word解决了这个问题.但我仍然对使用ComAutomationFactory的动态值如何使其工作非常感兴趣. 这可能更像是一个C#4.0问题,但我想要做的是利用受信任的SL4应用程序中的ComAutomationFactory类来加载Word文档,更改一些文本并...

最有效的C#SharePoint List迭代【代码】

我在C#中为SharePoint webpart做一些自定义代码.具体来说,我正在进行测验,我的主要观点是解决问题清单,答案选择和正确答案. 在测验的最后阶段,我需要检查用户根据列表中的正确答案选择的答案.目前,我正在做以下检查是否每个都是正确的,我假设它不是很有效,因为它遍历每个问题.是否有一种方法,特别是对于SPList foreach循环,哪种方法更有效?// 1. Store questions and answers in classList<submittedAnswers> answeredQuestions =...

c# – 具有非常快速的迭代和良好的添加和移除速度的集合

我正在追踪一个可以快速迭代的集合.我也会定期添加项目和删除(特定)项目,因此理想情况下这些操作也会很快. 我正在开发xbox,因此仅限于紧凑的框架(或多或少).将垃圾和对象分配保持在最低限度非常重要,因此我可以为我的对象预先分配空间的任何事情都会很棒. 我将在集合中存储uints(但如果需要可以是int).一般的解决方案会很好,因为我相信我将来会有需求. 一个.net集合将是理想的,没有一个轻量级和开源的东西会很棒. 是否有适合我需求...

c# – 如何迭代当前页面上的所有文本框【代码】

说我添加了很多文本框.如何迭代或循环遍历所有文本框并进行一些检查.检查每个文本框的内容是否为数字. 下面是winForm的代码,如何在WinRT中进行操作?foreach (Control item in GroupBox1.Controls) {if (item.GetType() == typeof(TextBox)){if (string.IsNullOrEmpty( ((TextBox)item).Text)){//Empty text in this box}} }谢谢.解决方法:这就是你想要的方式.public MainPage() {this.InitializeComponent();Loaded += MainPage_L...

C# 迭代器【代码】

using System; using System.Collections; class App{public static void Main(){foreach (int number in SomeNumbers()){Console.WriteLine(number.ToString() + " ");}//Console.WriteLine(SomeNumbers().MoveNext());// Output: 3 5 8// Console.ReadKey();}public static IEnumerable SomeNumbers(){yield return 3;yield return 5;yield return 8;} }

C# foreach 值类型及引用类型迭代变量改变的方式

C#中foreach不能改变迭代变量的值 然而此种说法只适用与值类型,更改值类型时会改变在栈上的内存分布 引用类型由于是引用地址的变更,不影响内存分布,所以能够在foreach中更改 至于引用类型中的特殊string类型,猜想是因为string类型的变更不是地址的更改,而是会在堆上面重新开辟一块,所以应该也是会影戏到内存分布

C# 可空类型 匿名方法 迭代器【图】

可空类型Demousing System;namespace NullDemo {class Program{static void Main(string[] args){//?语法糖DateTime? date= null;int? a = null;//获取默认值DateTime c = date.GetValueOrDefault();int d = a.GetValueOrDefault();//空合并操作符号??左边为null时取右边DateTime dateNew = date ?? DateTime.Now;int b = a ?? 123;Console.WriteLine(dateNew);Console.WriteLine(b);Console.WriteLine("default DateTime"+c);//00...