草庐IT

access-modifiers

全部标签

c# - 我应该关注 linq 查询中的 "access to modified closure"吗?

我有一个显示错误的linq查询:如果集合的源是一个linq查询,每当我尝试访问我正在迭代的变量时,我都会看到这个错误。我想这个错误只是告诉我变量可能会改变,或者类似的东西? 最佳答案 此错误告诉您查询中对pubConfig的引用将使用pubConfig的值在评估查询时,而不是在您定义它并将其存储在pubConfigSettings中时。实际上,如果“当场”评估查询就没问题。如果您保留它供以后评估,而pubConfig的值在此期间发生变化,您将遇到意想不到的结果。 关于c#-我应该关注li

c# - Azure key 保管库 : access denied

我有以下用于从Azurekey保管库获取secret的代码:publicstaticasyncTaskGetToken(stringauthority,stringresource,stringscope){varauthContext=newAuthenticationContext(authority);ClientCredentialclientCred=newClientCredential(...);//appid,appsecretAuthenticationResultresult=awaitauthContext.AcquireTokenAsync(resource,c

c# - 为什么我在 WPF 用户控件上看到 "member is not recognized or is not accessible"错误?

我有一个带有公共(public)属性的自定义用户控件,我希望能够在XAML中进行设置。在下面。TestControl.xamlTestControl.xaml.csusingSystem.Windows.Controls;namespaceMyProject.Controls{publicpartialclassTestControl:UserControl{publicstringTestMe{get;set;}publicTestControl(){InitializeComponent();}}}然后,在我的MainWindow.xaml文件中,我尝试包含以下内容:但是,即使Vi

c# - 如何以编程方式在 C# 中创建 Microsoft Access 数据库?

如果MicrosoftAccess数据库文件不存在,如何在C#中创建它? 最佳答案 最简单的答案是在您的程序中嵌入一个空的.mdb/.accdb文件并将其写入磁盘。正确答案是将COMInterop与ADOX库一起使用:varcat=newADOX.Catalog()cat.Create(connectionString);请记住使用OleDbConnectionStringBuilder生成连接字符串。 关于c#-如何以编程方式在C#中创建MicrosoftAccess数据库?,我们在S

c# - C# 中接口(interface)成员的访问修饰符

我从以下属性中收到编译错误。错误是:"Themodifier'public'isnotvalidforthisitem"publicSystem.Collections.Specialized.StringDictionaryIWorkItemControl.Properties{get{returnproperties;}set{properties=value;}}但是如果我删除IWorkItemControl它编译正常。为什么我会收到此错误以及在签名中包含/不包含接口(interface)名称有什么区别? 最佳答案 Expli

c# - WPF 调度程序 {"The calling thread cannot access this object because a different thread owns it."}

首先我需要说我是WPF和C#的菜鸟。应用程序:创建Mandelbrot图像(GUI)在这种情况下,我的调度员工作得很好:privatevoidprogressBarRefresh(){while((con.Progress)尝试使用以下代码执行此操作时,我收到了消息(标题):bmp=BitmapSource.Create(width,height,96,96,pf,null,rawImage,stride);this.Dispatcher.Invoke(DispatcherPriority.Send,newAction(delegate{img.Source=bmp;ViewBox.C

c# - 为什么使用类级访问修饰符而不是对象级?

在使用C#时,我最近意识到我可以调用Foo对象的私有(private)函数来自Foo的静态函数,甚至来自其他Foo对象。在了解了所有关于访问修饰符的知识之后,这对我来说听起来很奇怪。据我所知,当函数执行属于某种内部流程的一部分时,您将函数设为私有(private)。只有对象本身知道何时使用这些函数,因为其他对象不应该/不能控制对象的流程。是否有任何理由可以将同一类的其他对象排除在这个非常简单的规则之外?根据要求,一个例子:publicclassAClass{privatevoiddoSomething(){/*Dosomethinghere*/}publicvoidaFunction(

c# - LINQ to Entities Group By 表达式给出 'Anonymous type projection initializer should be simple name or member access expression'

我在这个表达式中遇到了上述错误:varaggregate=fromtinentities.TraceLinesjoinminentities.MethodNames.Where("it.NameLIKE@searchTerm",newObjectParameter("searchTerm",searchTerm))ont.MethodHashequalsm.MethodHashwhere(t.CallTypeId&(int)types)==t.CallTypeId&&t.UserSessionProcessId==m_SessionIdgrouptbym.Nameintodselect

c# - T4代码生成: access types in current project

使用T4代码生成,是否可以访问当前项目中定义的类型?例如,如果我有一个接口(interface)并且我想将它的实现委托(delegate)给另一个类,即interfaceIDoSomething{publicvoiddo_something();}classDoSomethingImpl:IDoSomething{publicvoiddo_something(){//implementation...}}classSomeClass:IDoSomething{IDoSomethingm_doSomething=newDoSomethingImpl();//forwardcallstoi

c# - 防止 visual studio 将 setter 方法限制为内部

好吧,我使用visualstudio2015CE,更新2。我通常做的一种提高效率的技巧是创建空模型类,例如:publicclassPersonModel{}然后在选择表达式中使用它们,例如:db.People.Where(p=>someCondition).Select(p=>newPersonModel{Id=p.Id,Name=p.Name,//setotherproperties}).ToList();然后我转到还不存在的属性Id和Name,...然后按Control+。要求visualstudio为我生成属性Id。一切都很好,但它会创造:publicintId{get;inte