为什么备选的顺序在正则表达式中很重要?

码 using System; using System.Text.RegularExpressions; namespace RegexNoMatch { class Program { static void Main () { string input = “a foobar& b”; string regex1 = “(foobar|foo)&?”; string regex2 = “(foo|foobar)&?”; string replace = “$1”; Console.WriteLine(Regex.Replace(input, regex1, replace)); Console.WriteLine(Regex.Replace(input, regex2, replace)); Console.ReadKey(); } } } 预期产出 a foobar b a foobar b 实际输出 a foobar b […]

Windows窗体中的C#垂直标签

是否可以在Windows窗体中垂直显示标签?

如何实现网页的实时数据

(这是一个Q / A风格的问题,旨在成为那些提出类似问题的人的首选资源。很多人似乎偶然发现这样做的最佳方式,因为他们不知道所有的选择许多答案都是ASP.NET特有的,但AJAX和其他技术确实在其他框架中具有等价物,例如socket.io和SignalR。) 我有一个我在ASP.NET中实现的数据表。 我希望实时或接近实时地显示页面上此基础数据的更改。 我该怎么办? 我的型号: public class BoardGame { public int Id { get; set;} public string Name { get; set;} public string Description { get; set;} public int Quantity { get; set;} public double Price { get; set;} public BoardGame() { } public BoardGame(int id, string name, string description, int quantity, double […]

如何从Chrome和Firefox获取打开网页的url?

我正在编写一个系统托盘应用程序,需要检查基于内部网络的应用程序是否已打开。 我可以使用以下方法检查IE: SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows(); string filename; bool sdOpen = false; foreach (SHDocVw.InternetExplorer ie in shellWindows) { filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); if (filename.Equals(“iexplore”)) { string[] urlParts = (ie.LocationURL.ToString()).Split(‘/’); string website = urlParts[2]; if (website == “myApp:8080”) { sdOpen = true; }; } } if (sdOpen) { Console.WriteLine(“App is open”); } else { Console.WriteLine(“App is […]

在C#中获取/设置文件所有者

我需要读取和显示文件的所有者(用于审计目的),并且可能还要更改它(这是次要要求)。 有没有好的C#包装器? 快速谷歌后,我发现只有WMI解决方案和PInvoke GetSecurityInfo的建议

使用log4net捕获用户名

我目前将所有log4net事件写入数据库,它似乎工作正常。 要捕获登录的用户帐户,我使用以下代码: HttpContext context = HttpContext.Current; if (context != null && context.User != null && context.User.Identity.IsAuthenticated) { MDC.Set(“user”, HttpContext.Current.User.Identity.Name); } 代码似乎没问题,除了没有与之关联的用户上下文的事件(即我们公共网页上的用户)。 在这种情况下,log4net捕获似乎有时写入最后登录的用户帐户(坏),有时写入空(好)。 任何人都有这个function在所有情况下都可靠地工作? 我相信我看到一条说明MDC不再是推荐使用的function,但我无法找到任何推荐的替代品。 注意:我发现MDC设置了帐户名称很奇怪,但如果没有用户处于活动状态,则永远不会清除。 这可能是问题的一部分。 但是,我没有找到任何也清除用户名的MDC代码提取。

在C#中编写表单时无法查看设计器

我正在关注winforms的这个教程,到目前为止,教程正在编写表单而不使用工具箱。 我相信它很快就会更深入地介绍工具箱。 在本教程之后,我在以下两段代码中进行了部分类: 第一档 : using System; using System.Windows.Forms; public class Numeric : System.Windows.Forms.TextBox { public Numeric() { } } public partial class Exercise { private Numeric txtbox; System.ComponentModel.Container components; } 第二档 : using System; using System.Windows.Forms; public partial class Exercise : Form { private void InitializeComponent() { txtbox = new Numeric(); Controls.Add(txtbox); } public […]

从资源加载图像

我想加载这样的图像: void info(string channel) { //Something like that channelPic.Image = Properties.Resources.+channel } 因为我不想这样做 void info(string channel) { switch(channel) { case “chan1”: channelPic.Image = Properties.Resources.chan1; break; case “chan2”: channelPic.Image = Properties.Resources.chan2; break; } } 这样的事情可能吗?

C#版本的OpenSSL EVP_BytesToKey方法?

我正在寻找OpenSSL EVP_BytesToKey函数的直接.NET实现。 我发现的最接近的是System.Security.Cryptography.PasswordDeriveBytes类(和Rfc2898DeriveBytes ),但它似乎略有不同 ,并且不生成与EVP_BytesToKey相同的密钥和iv 。 我也发现这个实现似乎是一个好的开始,但没有考虑迭代计数。 我意识到有OpenSSL.NET,但它只是本机openssl DLL的包装,而不是“真正的”.NET实现。

简单的冒泡排序c#

int[] arr = {800,11,50,771,649,770,240, 9}; int temp = 0; for (int write = 0; write < arr.Length; write++) { for (int sort = 0; sort arr[sort + 1]) { temp = arr[sort + 1]; arr[sort + 1] = arr[sort]; arr[sort] = temp; } } Console.Write(“{0} “, arr[write]); } 我试图做的就是使用这个数组进行简单的冒泡排序。 我想弄清楚为什么排序搞砸了。 例如,这里的数组是{800,11,50,771,649,770,240, 9} : 以下是显示的内容: 11, […]