Questions tagged «c#»

C#(发音为“ See Sharp”)是由Microsoft开发的一种高级,静态类型的多范例编程语言。C#代码通常针对Microsoft的.NET系列工具和运行时,其中包括.NET Framework,.NET Core和Xamarin。使用此标记可解决有关用C#或C#正式规范编写的代码的问题。

2
通用方法如何,何时何地具体化?
这个问题让我想知道通用方法的具体实现在哪里真正存在。我已经尝试过Google,但没有提出正确的搜索条件。 如果我们举这个简单的例子: class Program { public static T GetDefault<T>() { return default(T); } static void Main(string[] args) { int i = GetDefault<int>(); double d = GetDefault<double>(); string s = GetDefault<string>(); } } 在我的脑海中,我一直认为在某个时候它会导致实现具有3种必要的具体实现,以便在天真伪整型中,我们将拥有这种逻辑的具体实现,其中所使用的特定类型会导致正确的堆栈分配等。 。 class Program { static void Main(string[] args) { int i = GetDefaultSystemInt32(); double d = GetDefaultSystemFloat64(); …
72 c#  .net  generics 

9
快速傅立叶变换(FFT)在C#中的实现
关闭。此问题不符合堆栈溢出准则。它当前不接受答案。 想改善这个问题吗?更新问题,使其成为Stack Overflow的主题。 3年前关闭。 改善这个问题 在哪里可以找到C#中免费,快速,可靠的FFT实现? 那可以用在产品上吗?还是有任何限制?

6
为什么要检查此!= null?
有时,我喜欢花一些时间查看.NET代码,以了解幕后如何实现事情。我在String.Equals通过Reflector查看方法时偶然发现了这颗宝石。 C# [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public override bool Equals(object obj) { string strB = obj as string; if ((strB == null) && (this != null)) { return false; } return EqualsHelper(this, strB); } 白介素 .method public hidebysig virtual instance bool Equals(object obj) cil managed { .custom instance void System.Runtime.ConstrainedExecution.ReliabilityContractAttribute::.ctor(valuetype System.Runtime.ConstrainedExecution.Consistency, valuetype …
72 c#  .net  clr  reflector 

5
整数加总布鲁斯,短+ =短问题
C#中的程序: short a, b; a = 10; b = 10; a = a + b; // Error : Cannot implicitly convert type 'int' to 'short'. // we can also write this code by using Arithmetic Assignment Operator as given below a += b; // But this is running successfully, why? …
72 c#  types  int  short 

12
ILMerge最佳做法
您是否使用ILMerge?您是否使用ILMerge合并多个程序集以简化dll的部署?将组件合并在一起后,您是否发现生产中的部署/版本问题? 我正在寻找有关使用ILMerge来减少部署冲突的建议,如果可能的话。
72 c#  .net  deployment  ilmerge 

8
Application.Run()和Form.ShowDialog()有什么区别?
在我的应用程序中,如果登录成功,我想先显示一个登录表单,然后显示主表单。目前,我正在执行以下操作: var A = new LoginForm(); if ( A.ShowDialog() == DialogResult.OK ) Application.Run(new MainForm()); 但是后来我开始怀疑-的目的是什么Application.Run()?为什么不这样做(new MainForm()).ShowDialog()呢?有什么不同?而实现我想要的目标的正确方法是什么?
72 c#  winforms 


6
使用JavaScript / jQuery重定向到ASP.NET MVC中的另一个页面
我想使用JavaScript / jQuery / Ajax从ASP.NET MVC 3.0中的一页重定向到另一页。在按钮单击事件中,我已经编写了如下的JavaScript代码。 function foo(id) { $.post('/Branch/Details/' + id); } 我的控制器代码是这样的: public ViewResult Details(Guid id) { Branch branch = db.Branches.Single(b => b.Id == id); return View(branch); } 当我单击按钮时,它正在BranchController内调用Details动作,但不会返回到Details视图。 我没有收到任何错误或异常。在Firebug中显示状态200 OK 。我的代码有什么问题,如何重定向到“详细信息”视图页面?

1
我可以从DirectorySearcher获得1000条以上的记录吗?
我只是注意到结果的返回列表限制为1000。我的域(HUGE域)中有1000多个组。如何获得超过1000条记录?我可以从以后的唱片开始吗?我可以将其划分为多个搜索吗? 这是我的查询: DirectoryEntry dirEnt = new DirectoryEntry("LDAP://dhuba1kwtn004"); string[] loadProps = new string[] { "cn", "samaccountname", "name", "distinguishedname" }; DirectorySearcher srch = new DirectorySearcher(dirEnt, "(objectClass=Group)", loadProps); var results = srch.FindAll(); 我试图设置srch.SizeLimit = 2000; ,但这似乎不起作用。有任何想法吗?


5
C#:DateTime.Now Month输出格式
在此C#代码段中,作为输出DateTime.Now.Month.ToString()返回7。 我想07作为返回值。 当月份只有1位数字时,我该怎么做才能添加前导零?
72 c# 

7
System.Security.SecurityException:找不到源,但是无法搜索某些或所有事件日志。无法访问的日志:安全性
我正在尝试创建Windows服务,但是当我尝试安装它时,它会回滚并出现以下错误: System.Security.SecurityException:找不到源,但是无法搜索某些或所有事件日志。不可访问的日志:安全性。 我不知道这意味着什么-我的应用程序只有最低要求,因为我只是先进行测试。 我的安装程序代码: namespace WindowsService1 { [RunInstaller(true)] public partial class ProjectInstaller : System.Configuration.Install.Installer { public ProjectInstaller() { //set the privileges processInstaller.Account = ServiceAccount.LocalSystem; processInstaller.Username = null; processInstaller.Password = null; serviceInstaller.DisplayName = "My Service"; serviceInstaller.StartType = ServiceStartMode.Manual; //must be the same as what was set in Program's constructor serviceInstaller.ServiceName = …

3
WPF C#路径:如何从具有路径数据的字符串获取代码中的几何(不在XAML中)
我想在代码中生成WPF Path对象。 在XAML中,我可以这样做: <Path Data="M 100,200 C 100,25 400,350 400,175 H 280"> 如何在Code中做同样的事情? Path path = new Path(); Path.Data = "foo"; //This won't accept a string as path data. 是否有可用的类/方法将带PathData的字符串转换为PathGeometry或类似的字符串? 当然可以以某种方式解析XAML并转换数据字符串吗?
72 c#  wpf  path 

4
找不到OWIN HttpListener
当我尝试开始时: WebApp.Start<SrvcHst>(new StartOptions { Port = 9956, ServerFactory = "Microsoft.Owin.Host.HttpListener" }); 我得到以下异常。可能是根本原因? System.MissingMemberException was caught HResult=-2146233070 Message=The server factory could not be located for the given input: Microsoft.Owin.Host.HttpListener Source=Microsoft.Owin.Hosting StackTrace: at Microsoft.Owin.Hosting.Engine.HostingEngine.ResolveServerFactory(StartContext context) at Microsoft.Owin.Hosting.Engine.HostingEngine.Start(StartContext context) at Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start(StartOptions options) at Microsoft.Owin.Hosting.Starter.HostingStarter.Start(StartOptions options) at Microsoft.Owin.Hosting.WebApp.StartImplementation(IServiceProvider services, StartOptions options) at Microsoft.Owin.Hosting.WebApp.Start(StartOptions options) …

1
将集合绑定到StackPanel
我想获取一个对象集合并将其绑定到StackPanel,因此基本上来说,如果该集合具有4个元素,应该在应该产生4个按钮的堆栈面板内部说。 我尝试过...但是无论如何我都不认为这是正确的方法。我过去曾使用DataTemplated做这种想法。.如果我错了,请纠正我。 这是我的假模特 public class MockModel { public ObservableCollection<MockNode> Nodes; public MockModel() { Nodes = new ObservableCollection<MockNode>(); } } public class MockNode { public MockNode() { } private string itemname; public string ItemName { get { return this.itemname; } set { this.itemname = value; } } } 在代码中,我像这样设置DataContext ... // …

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.