Tag: .net

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

码 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 […]

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

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

在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 […]

C#版本的OpenSSL EVP_BytesToKey方法?

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

使用所有单元格格式将dataGridView导出到Excel

我有这个代码,我知道它运行得很快 CopyAlltoClipboard(dataGridViewControl); Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); xlWorkSheet.Name = page.Name; Excel.Range CR = (Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Range[“A1”]).EntireColumn.Delete(null); // delete the first column that has rows indexes xlWorkBook.SaveAs(fileName); private void CopyAlltoClipboard(DataGridView […]

.Net Core 1.1中的传递引用

在.NET Core 1.1和Visual Studio 2017 RC中开发示例Web应用程序时,我意识到以下内容: 如你看到的: ClassLibrary3引用了ClassLibrary2, 和ClassLibrary2引用ClassLibrary1 我在ClassLibrary3类的Class3中编写了一个简单的方法,而Intellisense允许我只使用Class1来编写类的名称,我的意思是,没有对ClassLibrary1项目进行显式引用。 我在这里错过了一些观点吗? 我不希望有人只是来看看ClassLibrary2。 谢谢。

使用参数执行查询

我想从C#执行.sql脚本。 基本上,脚本会在一些不同的表中插入一行。 关键是我在C#代码中有值,我需要传递给.sql查询。 这些值将在程序执行期间收集。 这是我想从C#代码执行的查询: INSERT INTO [DB].[dbo].[User] ([Id] ,[AccountId] ,[FirstName] ,[LastName] ,[JobTitle] ,[PhoneNumber] ) VALUES (’00A640BD-1A0D-499D-9155-BA2B626D7B68′ ,’DCBA241B-2B06-48D7-9AC1-6E277FBB1C2A’ ,’Mark’ ,’Wahlberg’ ,’Actor’ ,’9889898989′]) GO 这些值会不时变化,即它们是用C#代码捕获的,需要通过。 任何人都可以帮我这样做..我正在学习C#和SQL。 非常感谢。

在C#中实现生产者/消费者模式

如何使用事件和代理在C#中实现Producer / Consumer模式? 在使用这些设计模式时,我需要注意什么? 我需要注意哪些边缘情况?

如何XML序列化字典

我已经能够以这种方式序列化IEnumerable: [XmlArray(“TRANSACTIONS”)] [XmlArrayItem(“TRANSACTION”, typeof(Record))] public IEnumerable Records { get { foreach(Record br in _budget) { yield return br; } } } 但是,我意识到现在我需要一个包含集合Dictionary (RecordCollection实现IEnumerable)的Dictionary 。 我怎样才能做到这一点?

当C#在同一个包含的类中时,为什么以及如何允许访问类本身之外的私有变量?

我不知道这个问题是否足够描述,但为什么以及这种行为是如何存在的? public class Layer { public string Name { get; set; } private IEnumerable children; public IEnumerable Children { get { return this.children.Where ( c => c.Name != null ).Select ( c => c ); } set { this.children = value; } } public Layer ( ) { this.children = new List ( ); // […]