草庐IT

check_private_key

全部标签

c# - 您应该对私有(private)方法进行 XML 注释吗?

所以我在我的代码中使用XML注释来帮助解释公共(public)方法和公共(public)成员,另一位开发人员提到并非我的所有方法都有XML注释。我使用的规则是,如果是公共(public)的或protected,则添加XML注释,如果是私有(private)的,则不添加。这听起来合乎逻辑吗?或者有什么理由让您将XMLComment设为私有(private)方法? 最佳答案 关于评论没有严格的规定,但我认为评论公共(public)/内部/protected方法是好的。有时我会在私有(private)方法不是很清楚的时候注释它们。理想情况

c# - 匿名委托(delegate)中捕获的私有(private)字段

classA{publiceventEventHandlerAEvent;}classB{privateA_foo;privateint_bar;publicvoidAttachToAEvent(){_foo.AEvent+=delegate(){...UseBar(_bar);...}}}由于delegate捕获变量this._bar,它是否隐含地持有B的实例?B的实例是否会通过事件处理程序引用并由A的实例捕获变量?如果_bar是AttachToAEvent方法的局部变量,会有不同吗?因为在我的例子中,A的实例比B的实例生命周期长得多并且小得多,我担心会导致“内存泄漏”这样做。

c# - 如何使用反射获得重载的私有(private)/ protected 方法

usingSystem;usingSystem.Reflection;namespaceReflection{classTest{protectedvoidmethodname(inti){Console.WriteLine(("intheworldofthereflection-onlyi"));Console.Read();}protectedvoidmethodname(inti,intj){Console.WriteLine(("intheworldofthereflectioni,j"));Console.Read();}}classProgram{staticvoidMai

c# - 根据 item.key 获取字典项的索引

如何根据元素键找到字典元素的索引?我正在使用以下代码来浏览字典:foreach(varentryinfreq){varword=entry.Key;varwordFreq=entry.Value;inttermIndex=??????;}有人能帮忙吗? 最佳答案 Dictionary中没有索引的概念。您不能依赖Dictionary中项目的任何顺序。OrderedDictionary可能是替代方案。varfreq=newOrderedDictionary();//...foreach(varentryinfreq){varword=e

c# - ASP.NET : Check for click event in page_load

在C#中,如何检查是否在页面加载方法中单击了链接按钮?我需要知道在触发点击事件之前它是否被点击。 最佳答案 if(IsPostBack){//getthetargetofthepost-back,willbethenameofthecontrol//thatissuedthepost-backstringeTarget=Request.Params["__EVENTTARGET"].ToString();} 关于c#-ASP.NET:Checkforclickeventinpage_lo

c# - 绑定(bind)到资源 key ,WPF

我有一个包含一些图片的ResourceDictionary:我已经为TreeView项目创建了一个HierarchicalTemplate,如下所示:现在,当项目显示时:文本block显示FolderItemImage显示第一张图片第二张图片未显示。整个想法是将项目图像设置为存储在资源中的图像,但不幸的是,上面介绍的技术不起作用,现在我知道原因了:结果:Anunhandledexceptionoftype'System.Windows.Markup.XamlParseException'occurredinPresentationFramework.dllAdditionalinfor

c# - 阻止访问私有(private)成员变量?强制使用公共(public)属性(property)?

我使用的是.NET2.0,因此无法访问自动属性。所以我必须求助于以下编码私有(private)变量和公共(public)属性的方法privatestringm_hello=null;publicstringHello{get{returnm_hello;}set{m_hello=value;}}对于上述private/public成员的包含类的方法,是否有限制访问private变量的方法?我不喜欢我可以使用m_hello或Hello。谢谢。 最佳答案 正如其他人所建议的那样,这应该是一个答案...当面向.NET2.0时,您仍然可以在

c# - Entity Framework 4 : How to find the primary key?

我正在尝试使用EF4创建一个通用方法来查找对象的主键。例子publicstringGetPrimaryKey(){...}为了提供更多信息,我正在使用TekpubStarterKit,下面是我正在尝试启动和运行的类(class)usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Data.Objects;usingSystem.Data.Objects.ELinq;usingSystem.Data.Linq;usingWeb.Infrastructure.Sto

c# - 具有私有(private)密封类的 Activator.CreateInstance

我正在尝试新建一个LocalCommand实例,它是System.Data.SqlClient.SqlCommandSet的私有(private)类。我似乎能够很好地获取类型信息:AssemblysysData=Assembly.Load("System.Data,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089");localCmdType=sysData.GetType("System.Data.SqlClient.SqlCommandSet+LocalCommand");但是当我尝试实例化Activat

c# - 私有(private)成员在 API 方法调用中突然为 null

发生了奇怪的事情:在我的网络api中,我在使用Ninject解析时将一个存储库注入(inject)到Controller中。存储库存储在私有(private)只读成员变量中。工作得很好!当一个api方法被调用时,我访问了这个变量-只是发现它突然变成了null!伪例子:publicclassMyController:ApiController{privatereadonlyIRepo_repo;publicMyController(IReporepo){Guard.AgainstNullArgument("repo",repo);//guardingto//makesureit'snot