Questions tagged «c#»

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

14
高质量图像缩放库
关闭。此问题不符合堆栈溢出准则。它当前不接受答案。 想改善这个问题吗?更新问题,使其成为Stack Overflow 的主题。 5年前关闭。 改善这个问题 我想在C#中以与Photoshop一样好的质量缩放图像。是否有任何C#图像处理库可用于执行此操作?

6
使用Sha256散列字符串
我尝试使用SHA256哈希字符串,我使用以下代码: using System; using System.Security.Cryptography; using System.Text; public class Hash { public static string getHashSha256(string text) { byte[] bytes = Encoding.Unicode.GetBytes(text); SHA256Managed hashstring = new SHA256Managed(); byte[] hash = hashstring.ComputeHash(bytes); string hashString = string.Empty; foreach (byte x in hash) { hashString += String.Format("{0:x2}", x); } return hashString; } } 但是,与我的朋友php和在线生成器(例如This …
141 c#  string  hash  sha256 

10
如何清除C#中的事件订阅?
采取以下C#类: c1 { event EventHandler someEvent; } 如果有很多订阅c1的someEvent活动,而我想全部清除,那么实现此目的的最佳方法是什么?还请注意,此事件的订阅可能是lambdas /匿名代表。 目前,我的解决方案是向该ResetSubscriptions()方法添加一个c1设置someEvent为null的方法。我不知道这是否会带来看不见的后果。
141 c#  .net  events  delegates 


16
为什么不可能覆盖仅getter的属性并添加setter?[关闭]
已关闭。这个问题是基于观点的。它当前不接受答案。 想改善这个问题吗?更新问题,以便通过编辑此帖子以事实和引用的形式回答。 2年前关闭。 改善这个问题 为什么不允许以下C#代码: public abstract class BaseClass { public abstract int Bar { get;} } public class ConcreteClass : BaseClass { public override int Bar { get { return 0; } set {} } } CS0546'ConcreteClass.Bar.set':无法覆盖,因为'BaseClass.Bar'没有可覆盖的集合访问器



12
检查NameValueCollection中是否存在键
有没有一种快速简单的方法来检查键是否存在于NameValueCollection中而无需遍历它? 寻找类似Dictionary.ContainsKey()之类的东西。 当然,有很多方法可以解决此问题。只是想知道是否有人可以帮助我挠痒。

5
是否有更安全的方式将项目安全地添加到Dictionary <>中?
我需要将键/对象对添加到字典中,但是我当然需要首先检查该键是否已经存在,否则会收到“ 键在字典中已存在 ”错误。下面的代码解决了这个问题,但是很笨拙。 什么是更优雅的方法而不做这样的字符串助手方法呢? using System; using System.Collections.Generic; namespace TestDictStringObject { class Program { static void Main(string[] args) { Dictionary&lt;string, object&gt; currentViews = new Dictionary&lt;string, object&gt;(); StringHelpers.SafeDictionaryAdd(currentViews, "Customers", "view1"); StringHelpers.SafeDictionaryAdd(currentViews, "Customers", "view2"); StringHelpers.SafeDictionaryAdd(currentViews, "Employees", "view1"); StringHelpers.SafeDictionaryAdd(currentViews, "Reports", "view1"); foreach (KeyValuePair&lt;string, object&gt; pair in currentViews) { Console.WriteLine("{0} {1}", pair.Key, pair.Value); } …

5
RestSharp JSON参数发布
我试图对我的MVC 3 API进行非常基本的REST调用,而我传入的参数未绑定到action方法。 客户 var request = new RestRequest(Method.POST); request.Resource = "Api/Score"; request.RequestFormat = DataFormat.Json; request.AddBody(request.JsonSerializer.Serialize(new { A = "foo", B = "bar" })); RestResponse response = client.Execute(request); Console.WriteLine(response.Content); 服务器 public class ScoreInputModel { public string A { get; set; } public string B { get; set; } } // …

6
是否存在与Process.Start异步的等效项?
如标题所示,是否有Process.Start我可以等待的等效项(允许您运行其他应用程序或批处理文件)? 我正在玩一个小型控制台应用程序,这似乎是使用异步和等待的理想场所,但我找不到这种情况的任何文档。 我在想的是以下几方面的东西: void async RunCommand() { var result = await Process.RunAsync("command to run"); }
141 c#  async-await  c#-5.0 


7
如何在运行时指定[DllImport]路径?
实际上,我有一个C ++(工作中)的DLL,我想导入到我的C#项目中以调用它的功能。 当我指定DLL的完整路径时,它确实可以工作,如下所示: string str = "C:\\Users\\userName\\AppData\\Local\\myLibFolder\\myDLL.dll"; [DllImport(str, CallingConvention = CallingConvention.Cdecl)] public static extern int DLLFunction(int Number1, int Number2); 问题在于它将是一个可安装的项目,因此用户的文件夹将是不同的(例如:pierre,paul,jack,mum,dad等),具体取决于运行该文件的计算机/会话。 所以我希望我的代码更加通用,例如: /* goes right to the temp folder of the user "C:\\Users\\userName\\AppData\\Local\\temp" then go to parent folder "C:\\Users\\userName\\AppData\\Local" and finally go to the DLL's folder "C:\\Users\\userName\\AppData\\Local\\temp\\myLibFolder" */ string str = …
141 c#  c++  dll  constants  dllimport 

4
在IGrouping中获取“值”属性
我有一个像这样的数据结构 public DespatchGroup(DateTime despatchDate, List&lt;Products&gt; products); 我正在努力做... var list = new List&lt;DespatchGroup&gt;(); foreach (var group in dc.GetDespatchedProducts().GroupBy(i =&gt; i.DespatchDate)) { // group.Values is not correct... how do I write this? list.Add(new DespatchGroup(group.Key, group.Values); } 我显然不明白,IGrouping因为我看不到如何实际访问组中的数据记录!

3
C#将函数作为参数传递
我已经用C#编写了一个进行数值微分的函数。看起来像这样: public double Diff(double x) { double h = 0.0000001; return (Function(x + h) - Function(x)) / h; } 我希望能够传递任何功能,例如: public double Diff(double x, function f) { double h = 0.0000001; return (f(x + h) - f(x)) / h; } 我认为代表可以这样做(也许吗?),但是我不确定如何使用它们。 任何帮助将不胜感激。
141 c#  arguments 

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.