“使用”是否具有任何优势?

引用某些方法时,可以使用using或显式键入整个命名空间。 使用一种方法比另一种方法有任何速度优势,还是只是简单地输入整个命名空间? 谢谢

对“C:\ Windows \ system32 \ config \ systemprofile”路径的访问被拒绝

我正在使用Google Calendar Api和我的一个项目。 我不知道如何,但下面显示的错误是令人不安的。 AppFlowMetadata代码。 public class AppFlowMetadata : FlowMetadata { private static readonly IAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer { ClientSecrets = new ClientSecrets { ClientId = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com”, ClientSecret = “xxxxx_xxxxxxxxxxxxxxxxx” }, Scopes = new[] { CalendarService.Scope.Calendar }, DataStore = new FileDataStore(“Calendar.Api.Auth.Store”) }); public override string GetUserId(Controller controller) { var user = controller.Session[“UserID”]; if […]

以与创建相反的顺序处理对象?

我在我编写的代码中面临一个反复出现的问题:修改一些全局值(我将使用注册表值作为示例),然后尝试将修改恢复为原始状态。 我以为我会尝试使用IDisposable来解决这个问题。 创建时,对象将读取注册表值,将其存储在本地,然后进行修改。 当被破坏时,它将恢复设置。 它将使用这样的东西: using(RegistryModification mod = new RegistryModification(“HKCR\SomeValue”, 42)) { // reg value now modified to 42, do stuff } // Object gets disposed, which contains code to revert back the setting 如果只进行一次修改,应该工作得很好。 但是如果进行了多次修改,或者调用者没有使用’using’结构创建对象,我会发现出现问题。 public void Foo() { // assume HKCR\SomeValue starts as ’13’ // First object reads HKCR\SomeValue and stores ’13’, then […]

Windows Phone后退按钮问题

我有一个应用程序有2个表单,主要表单和属性表单,当我单击导航到属性的按钮,然后我单击后退按钮(硬件)我得到我期望的,我的应用程序返回到主窗体,但如果我应用属性并再次导航到主页并再次按下后退按钮我返回属性,如果我继续推回,我可以返回无限属性/主页,这是不好的,因为主页已更改其属性。 Good cases: MainPage —> properties –back–> MainPage (No properties were set) MainPage —> properties –set–> newMainPage MainPage —> properties –set–> MainPage –back–> closeApp Bad cases: MainPage —> properties –set–> MainPage –back–> properties –back–> oldMainPage MainPage —> properties –set–> newMainPage —> properties –set–> new_newMainPage –back–> properties –back–> oldMainPage –back–> properties –back–> old_oldMainPage 也许我可以删除导航缓存? 我试过这个,但编译器告诉我它是只读的: this.NavigationCacheMode […]

如何同时为C#类分配多个名称

有没有一种方法可以为C#类赋予多个名称,例如: Foo {} class AlternativeFooName是指Foo 我希望能够通过两个名称,Foo和AlternativeFooName访问Foo,但不必从Fooinheritance。 对此应用程序将为类提供一个长描述性名称,但在使用时可以缩写它,例如: 而不是Foo f = new Foo(); 能够使用具有相同效果的以下内容:F f = new F();

从多个林环境中获取Domain Local Group的所有成员

我有一个域本地组,它是林A中域A的一部分。 我试图迭代这个组中的所有成员。 它迭代遍历林A的所有域,但不会迭代域B中的任何组成员,在林B中。 是从不同的森林开始迭代相同代码的唯一方法吗? 我们已尝试使用System.DirectoryServices.AccountManagement类,但它们和Windows Server 2012域控制器似乎存在问题。 private List getUsersInGroup(string groupDN) { var users = new List(); using (DirectoryEntry de = new DirectoryEntry(“GC://rootDSE”)) { var rootName = de.Properties[“rootDomainNamingContext”].Value.ToString(); using (var userBinding = new DirectoryEntry(“GC://” + rootName)) { using (DirectorySearcher adSearch = new DirectorySearcher(userBinding)) { adSearch.ReferralChasing = ReferralChasingOption.All; adSearch.Filter = String.Format(“(&(memberOf={0})(objectClass=person))”, groupDN); adSearch.PropertiesToLoad.Add(“distinguishedName”); adSearch.PropertiesToLoad.Add(“givenname”); adSearch.PropertiesToLoad.Add(“samaccountname”); adSearch.PropertiesToLoad.Add(“sn”); […]

为什么在定义接口的方法和属性前面没有修饰符(public,private,protected)?

可能重复: 您是否有理由无法在方法或界面中定义访问修饰符? 你好, 我对接口感到好奇。 假设我有以下界面的定义 public interface IPersone { string FirstName { get; set; } string LastName { get; set; } int CalculateAge(int YearOfBirth); } 为什么在定义接口的方法和属性前面没有修饰符(public,private,protected)? 有什么理由吗? 谢谢你的帮助

C#窗口形成2个带有同步滚动的网格视图

我正在开发一个应用程序,其中从不同的数据源填充两个datagridviews。 我想有一个垂直滚动条,可以使两个网格视图同时工作(一起向上和向下滚动) 任何人都可以告诉我如何或指导我一个好的教程。

C#.Net Dll引用依赖项

我编写了一个DLL库MyLIB.dll (版本1.0.0 ),它依赖于第三方DLL库OtherLIB.dll (版本1.0.0 )。 库可以在NuGet上使用OtherLIB.dll ,我将通过NuGet包管理器将其添加到MyLIB.dll项目中。 现在让我们说我正在编写一个新的应用程序,比如MyAspNetMvcApp ,我正在通过NuGet向它添加MyLIB.dll (版本1.0.0 )。 它会自动添加OtherLIB.dll (版本1.0.0 ),因为它依赖于它。 一切都很好,但…… 一个月后,发布了新版本的OtherLIB.dll – 版本1.0.1 。 我正在通过NuGet更新它。 现在,我的ASP.NET MVC应用程序停止工作,因为MyLIB.dll引发了exception。 它期望版本1.0.0中的 OtherLIB.dll ,但已经使用了更新的版本。 在MyLIB.dll项目引用中,我可以看到OtherLIB.dll的 “特定版本”标志被设置为“False”,所以我不知道这里发生了什么…… 除了在web.config文件中提供程序集绑定之外,是否有可能以其他方式解决此问题? 我如何为MyLIB.dll添加对OtherLIB.dll的引用,以便在将OtherLIB.dll更新为较新版本时不会出现exception?

对基于C#/ .NET的良好词法分析器的建议

任何人都可以推荐一个优秀的基于.NET的词法分析器,最好用C#编写?