Tag: .net

在WinRT中的默认Web浏览器中打开URL

这个问题说明了一切。 基本上,我只想知道WinRT中的替代方法: Process.Start(“http://www.google.com/”);

.NET / SQL Server中的连接池?

在使用SQL Server数据库在.NET中开发应用程序时,编写自定义连接池代码是否必要或有利? 我知道ADO.NET为您提供了启用/禁用连接池的选项 – 这是否意味着它已内置到框架中而我不需要担心它? 为什么人们谈论编写自己的连接池软件?这与ADO.NET中内置的有何不同?

为什么从int到uint的隐式转换有效?

使用Casting null并不能作为灵感编译,而是来自Eric Lippert的评论: 这表明了一个有趣的案例。 “uint x =(int)0;” 即使int不能隐式转换为uint,也会成功。 我们知道这不起作用,因为无法将object分配给string : string x = (object)null; 但这确实如此,但直觉上它不应该: uint x = (int)0; 当int不能隐式转换为uint时,为什么编译器允许这种情况?

如何跟踪异步/等待任务是否正在运行

我正在尝试从基于事件的异步模式转换,我使用唯一的id和asynoperationmanager跟踪运行方法。 由于现在已从Windows 8应用程序中删除,我试图获得与Async / Await类似的效果,但无法弄清楚如何。 我想要实现的是类似的东西 private async Task updateSomething() { if(***the method is already running***) { runagain = true; } else { await someMethod(); if (runagain) { run the method again } } } 我正在努力的部分是找出方法是否正在运行。 我已经尝试创建一个Task并查看该异步方法和.status的状态,但它们看起来并不正确。 谢谢 更新:这是我在.net 4中使用的当前代码,以实现相同的结果。 _updateMetaDataAsync是基于事件的异步模式的类。 private void updateMetaData() { if (_updateMetaDataAsync.IsTaskRunning(_updateMetaDataGuid_CheckAllFiles)) { _updateMetaDataGuid_CheckAllFiles_Again = true; } else { _updateMetaDataGuid_CheckAllFiles_Again […]

当子结构具有LayoutKind.Explicit时,不遵循LayoutKind.Sequential

运行此代码时: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace StructLayoutTest { class Program { unsafe static void Main() { Console.WriteLine(IntPtr.Size); Console.WriteLine(); Sequential s = new Sequential(); sA = 2; sB = 3; s.Bool = true; s.Long = 6; sCInt32a = 4; sCInt32b = 5; int* ptr = (int*)&s; Console.WriteLine(ptr[0]); Console.WriteLine(ptr[1]); Console.WriteLine(ptr[2]); Console.WriteLine(ptr[3]); […]

在Unity容器中将null注册为实例

我有一个带可选依赖项的存储库类: class MyRepository : BaseRepository, IMyRepository { public MyRepository(IDataContext dataContext, ICacheProvider cacheProvider = null) : base(dataContext, cacheProvider) {} // … } cacheProvider参数的存在充当存储库的策略。 我想要像这样设置Unity容器: Container.RegisterType(new PerResolveLifetimeManager(), new InjectionConstructor()) .RegisterInstance(null) // ??? .RegisterType(); 也就是说没有为MyRepository指出具有一个参数的特定InjectionConstructor,而是使用带有null的默认构造函数作为cacheProvider参数。 有没有办法做到这一点?

使用Linq选择类的属性以返回IEnumerable

如果我有一个SortedList ,我想从该类返回一个新的IEnumerable属性,我该怎么做? 我尝试过SortedList.Select(x=>x.MyProperty, x.AnotherProperty)但它不起作用。 谢谢。

如何在WinForms中显示包含详细信息的消息框?

刚才我注意到,当属性设置为无效值时,Visual Studio会显示一个带有详细信息的消息框。 例如: 是否可以在WinForms中生成这种类型的消息框? 我试过以下代码: MessageBox.Show(“Error in Division Fill.\n” + ex.Message, “Information”, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxOptions.RightAlign); 但是这产生了以下错误: 错误24’System.Windows.Forms.MessageBox.Show(string,string,System.Windows.Forms.MessageBoxButtons,System.Windows.Forms.MessageBoxIcon,System.Windows.Forms.MessageBoxDefaultButton)’的最佳重载方法匹配无效的参数 G:\ Jagadeeswaran \ 11月17日\ MCS-SPS学校\ MCS-SPS学校\证书\ Transfer.cs 164 21 MCS-SPS学校 如何修复此错误并获取显示其他详细信息的消息框?

是否有一个委托,它不是C#中的MulticastDelegate?

我觉得答案是否定的? 如果没有,为什么我们将Delegate和MulticastDelegate类分开? 也许是因为“其他一些.NET语言”?

从枚举中获取下一个N个元素

上下文:C#3.0,.Net 3.5 假设我有一个生成随机数的方法(永远): private static IEnumerable RandomNumberGenerator() { while (true) yield return GenerateRandomNumber(0, 100); } 我需要将这些数字分组为10组,所以我想要像: foreach (IEnumerable group in RandomNumberGenerator().Slice(10)) { Assert.That(group.Count() == 10); } 我已经定义了Slice方法,但我觉得应该已经定义了一个。 这是我的Slice方法,仅供参考: private static IEnumerable Slice(IEnumerable enumerable, int size) { var result = new List(size); foreach (var item in enumerable) { result.Add(item); if (result.Count == size) { yield return […]