草庐IT

default-public

全部标签

c# 公共(public)嵌套类还是更好的选择?

我有一个控制电路,它有多个设置,并且可以连接任意数量的传感器(每个传感器都有自己的一组设置)。这些传感器只能与控制电路一起使用。我想像这样使用嵌套类:publicclassControlCircuitLib{//Fields.privateSettingscontrollerSettings;privateListattachedSensors;//Properties.publicSettingsControllerSettings{get{returnthis.controllerSettings;}}publicListAttachedSensors{get{returnthis

c# - Properties.Settings.Default.Save(); ->那个文件在哪里

我有一个使用“设置”的应用。要保存我使用的设置:Properties.Settings.Default.Save();阅读我使用的:Properties.Settings.Default.MyCustomSetting;在我的应用程序文件夹中,我只有exe文件。没有配置文件。我的应用程序运行良好,可以读写设置。如果该文件不在应用程序文件夹中,该文件位于何处? 最佳答案 在我的WindowsXP机器上,设置保存在C:\DocumentsandSettings\\ApplicationData\下某处名为user.config的文件中。

c# - 如何判断用户访问的是 "/Default.aspx"还是 "/"

我正在我的Global.asax.cs的Application_BeginRequest部分中编写。出于SEO目的,我正在尝试重定向正在查看的用户:http://www.example.com/Default.aspx到:http://www.example.com/我的问题是:我如何知道用户正在看哪个?我一直在使用:HttpContext.Current.Request.Url.*但是无论我访问哪一个,所有参数都是相同的。 最佳答案 您可以获取在用户浏览器中输入的路径:stringpath=Request.RawUrl;MSDN

c# - 为什么 List<T>.Sort 使用 Comparer<int>.Default 比等效的自定义比较器快两倍以上?

结果使用1000万个随机列表ints(每次相同的种子,重复10次的平均值):listCopy.Sort(Comparer.Default)需要314毫秒。使用sealedclassIntComparer:IComparer{publicintCompare(intx,inty){returnxlistCopy.Sort(newIntComparer())需要716毫秒。一些变化:使用structIntComparer而不是sealedclass:771毫秒使用publicintCompare(intx,inty){returnx.CompareTo(y);}:809毫秒评论Compar

c# - 如何获取基类的公共(public)静态方法?

我的基类有一个公共(public)静态方法,但是当我调用typeof(TDerived).GetMethods(BindingFlags.Public|BindingFlags.Static)时,我的方法没有返回。(TDerived当然以某种方式继承self的基类)。我在此查询的位置没有对我的基类的引用。我做错了什么? 最佳答案 使用BindingFlags.FlattenHierarchy标志:typeof(TDerived).GetMethods(BindingFlags.Public|BindingFlags.Static|B

c# - 在 switch case 中,如果我们将 "default"写为任何单词或单个字母,它不会抛出错误

在switch中,如果我们写任何单词或单个字母而不是default,它不会抛出错误。例如switch(10){case1:break;hello:break;}它运行时没有抛出错误。谁能解释一下这是如何工作的? 最佳答案 它正在编译,因为hello:是一个标签,因此可以作为goto的目的地。当我编译这个时,我收到了关于未引用标签的警告(因为我没有转到)这是您可以放入LINQPad的示例-您会注意到它同时打印“1”和“hello”:switch(1){case1:"1".Dump();gotohello;break;hello:"he

c# - Autofac - 自动注册错误 : No constructors can be found with 'Public binding flags'

这是我的Global.asax.cspublicvoidRegisterContainersUsingAutofac(){//http://elegantcode.com/2009/01/07/ioc-libraries-compared///http://www.codeproject.com/Articles/25380/Dependency-Injection-with-Autofac//https://code.google.com/p/autofac///http://api.autofac.org/varbuilder=newContainerBuilder();build

C# 字典性能 : Default string Comparer's GetHashCode() allocates memory in violation of guidelines, 从而破坏性能?

有anestablishedguideline获取哈希码不应分配内存,因为这会通过调用垃圾收集器对哈希表查找产生负面影响。然而,这个确切的失败是我所看到的我使用System.Collections.Generic.Dictionary的应用程序的配置文件在一个非常紧凑的循环中,我在分析器结果中发现以下内容:[3.47%]TryGetValue(TKey,TValue&)(...字典)[3.47%]FindEntry(TKey)(...字典)[3.47%]GetHashCode(string)(System.CultureAwareComparer)[3.46%]GetHashCodeO

c# - 抽象类中 'public'构造函数的相关性

抽象类中的“公共(public)”构造函数是否有任何相关性?我想不出任何可能的方法来使用它,在那种情况下它不应该被编译器视为错误(C#,不确定其他语言是否允许这样做)。示例代码:internalabstractclassVehicle{publicVehicle(){}}C#编译器允许编译此代码,但我无法从外部世界调用此构造函数。它只能从派生类中调用。所以它不应该只允许“protected”和“私有(private)”修饰符。请评论。 最佳答案 没有理由为抽象类使用公共(public)构造函数。我认为编译器没有提示的原因很简单,他们

C# 到 VB.NET : the **default** keyword?

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:Defaultvalueforgenerics好的,所以在将一些代码从C#转换为VB.NET时,我遇到了default关键字,我只是将其替换为nothing。这是正确的方法吗,或者是否有更好的关键字“翻译”?