Questions tagged «.net»

请勿使用有关.NET Core的问题,而应使用[.net-core]。.NET框架是主要为Microsoft Windows操作系统设计的软件框架。它包括基类库,公共语言运行时(通常称为CLR),公共类型系统(通常称为CTS)和动态语言运行时的实现。它支持多种编程语言,包括C#,VB.NET,F#和C ++ / CLI。

6
如何获得执行程序集的版本?
我正在尝试使用以下代码在C#3.0中获取执行程序集版本: var assemblyFullName = Assembly.GetExecutingAssembly().FullName; var version = assemblyFullName .Split(',')[1].Split('=')[1]; 还有另一种合适的方法吗?
169 c#  .net  .net-assembly 

7
如何遍历一个类的所有属性?
我有课 Public Class Foo Private _Name As String Public Property Name() As String Get Return _Name End Get Set(ByVal value As String) _Name = value End Set End Property Private _Age As String Public Property Age() As String Get Return _Age End Get Set(ByVal value As String) _Age = value …

5
LINQ:“包含”和一个Lambda查询
我有一个List<BuildingStatus>电话buildingStatus。我想检查它是否包含其字符代码(由返回GetCharCode())等于某个变量的状态v.Status。 遵循下面的(非编译)代码,有某种方法可以做到这一点? buildingStatus.Contains(item => item.GetCharValue() == v.Status)
168 c#  .net  list  linq  lambda 

3
创建PDF的最佳C#API
从目前的情况来看,这个问题不适合我们的问答形式。我们希望答案会得到事实,参考或专业知识的支持,但是这个问题可能会引起辩论,争论,民意调查或扩展讨论。如果您认为此问题可以解决并且可以重新提出,请访问帮助中心以获取指导。 8年前关闭。 您能推荐C#的任何PDF API吗?免费是最好的,但我不介意为此付费。
168 c#  .net  api  pdf-generation 

8
如何找到活动的app.config文件的路径?
我正在尝试完成此异常处理程序: if (ConfigurationManager.ConnectionStrings["ConnectionString"]==null) { string pathOfActiveConfigFile = ...? throw new ConfigurationErrorsException( "You either forgot to set the connection string, or " + "you're using a unit test framework that looks for "+ "the config file in strange places, update this file : " + pathOfActiveConfigFile); } 这个问题似乎仅在我使用nUnit时发生。

4
带out参数的Func <T>
我可以将带有out参数的方法作为Func传递吗? public IList&lt;Foo&gt; FindForBar(string bar, out int count) { } // somewhere else public IList&lt;T&gt; Find(Func&lt;string, int, List&lt;T&gt;&gt; listFunction) { } Func需要一个类型,因此out不能在那里编译,调用listFunction需要一个int,不允许out in。 有没有办法做到这一点?
167 c#  .net  linq  generics  func 

14
foreach与someList.ForEach(){}
显然,有很多方法可以迭代集合。好奇是否存在任何差异,或者为什么要使用一种方法来替代另一种方法。 第一类: List&lt;string&gt; someList = &lt;some way to init&gt; foreach(string s in someList) { &lt;process the string&gt; } 另一种方式: List&lt;string&gt; someList = &lt;some way to init&gt; someList.ForEach(delegate(string s) { &lt;process the string&gt; }); 我想想起来,您将可以指定一个可重用的委托,而不是上面使用的匿名委托...
167 c#  .net  generics  loops  enumeration 

11
BackgroundWorker vs背景线程
我对应该在Windows Form应用程序上使用的后台线程实现的选择有一个风格上的问题。目前,我BackgroundWorker在具有无限(while(true))循环的表单上。在此循环中,我用于WaitHandle.WaitAny保持线程休眠,直到发生感兴趣的事情为止。我等待的事件句柄之一是“ StopThread”事件,因此我可以跳出循环。从我重写时发出此事件信号Form.Dispose()。 我读过某个地方,该地方BackgroundWorker实际上是您不希望将UI与之捆绑在一起并具有有限结局的操作-例如下载文件或处理一系列项目。在这种情况下,“结束”是未知的,只有在关闭窗口时才知道。因此,对我而言,使用后台线程而不是BackgroundWorker为此目的更合适吗?

5
LINQ-左联接,分组依据和计数
假设我有以下SQL: SELECT p.ParentId, COUNT(c.ChildId) FROM ParentTable p LEFT OUTER JOIN ChildTable c ON p.ParentId = c.ChildParentId GROUP BY p.ParentId 如何将其转换为LINQ to SQL?我被困在COUNT(c.ChildId),生成的SQL似乎总是输出COUNT(*)。这是到目前为止我得到的: from p in context.ParentTable join c in context.ChildTable on p.ParentId equals c.ChildParentId into j1 from j2 in j1.DefaultIfEmpty() group j2 by p.ParentId into grouped select new { ParentId …
166 c#  .net  linq  linq-to-sql 

13
在C#代码中使用.NET 4.0元组是否是糟糕的设计决策?
在.net 4中添加了Tuple类之后,我一直试图确定在设计中使用它们是否是一个错误的选择。按照我的看法,元组可以是编写结果类的捷径(我敢肯定,还有其他用途)。 所以这: public class ResultType { public string StringValue { get; set; } public int IntValue { get; set; } } public ResultType GetAClassedValue() { //..Do Some Stuff ResultType result = new ResultType { StringValue = "A String", IntValue = 2 }; return result; } 等效于此: public Tuple&lt;string, int&gt; …



24
什么时候可以调用GC.Collect?
一般建议是,您不应GC.Collect从代码中调用,但是此规则的例外是什么? 我只能想到一些非常特殊的情况,在这些情况下强制进行垃圾回收是有意义的。 想到的一个示例是一项服务,该服务每隔一段时间醒来,执行一些任务,然后长时间睡眠。在这种情况下,最好强制执行一次收集以防止即将闲置的进程保留所需的更多内存。 还有其他情况下可以接受通话GC.Collect吗?

5
AppSettings与applicationSettings(.NET app.config / Web.config)的优缺点
在开发.NET Windows Forms Application时,我们可以在这些App.config标签之间进行选择以存储我们的配置值。哪一个更好? &lt;configuration&gt; &lt;!-- Choice 1 --&gt; &lt;appSettings&gt; &lt;add key="RequestTimeoutInMilliseconds" value="10000"/&gt; &lt;/appSettings&gt; &lt;!-- Choice 2 --&gt; &lt;configSections&gt; &lt;sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c5612342342" &gt; &lt;section name="Project1.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c5612342342" requirePermission="false" /&gt; &lt;/sectionGroup&gt; &lt;/configSections&gt; &lt;applicationSettings&gt; &lt;Project1.Properties.Settings&gt; &lt;setting name="TABLEA" serializeAs="String"&gt; &lt;value&gt;TABLEA&lt;/value&gt; &lt;/setting&gt; &lt;/Project1.Properties.Settings&gt; &lt;/applicationSettings&gt; &lt;/configuration&gt;

2
为什么HashSet <Point>比HashSet <string>慢得多?
我想存储一些像素位置而不允许重复,所以首先想到的是HashSet&lt;Point&gt;或类似的类。但是,与之相比,这似乎很慢HashSet&lt;string&gt;。 例如,此代码: HashSet&lt;Point&gt; points = new HashSet&lt;Point&gt;(); using (Bitmap img = new Bitmap(1000, 1000)) { for (int x = 0; x &lt; img.Width; x++) { for (int y = 0; y &lt; img.Height; y++) { points.Add(new Point(x, y)); } } } 大约需要22.5秒。 尽管以下代码(出于明显的原因,这不是一个很好的选择)仅花费1.6秒: HashSet&lt;string&gt; points = new HashSet&lt;string&gt;(); using (Bitmap …

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.