I have a problem with use one textBox in two Forms. I have string s = TextBox1.Text with Form1 and i need use this s on another Form2? How make it? Hmy that public static string dont worked... I have: public void button1_Click(object sender, EventArgs e) { public static string s = textBox1.Text; } This is not worked, i need use this "s" in another metod with another window :/ 将其
我在两个表单中使用一个文本框有问题。 我有Form1的字符串s = TextBox1.Text,我需要在另一个Form2上使用这个s? 如何做到这一点? 公共静态字符串不工作...我有:public void button1_Click(object sender,EventArgs e){public static string s = textBox1.Text; }这是行不通的,我需要在另一个窗口中使用这个“s”与另一个窗口:/ 将其设置为Form1上的公共静态属性,然后您可以从任何地方访问它。 //in form1 public sta
我如何将一个int数据类型转换为C#中的string数据类型? string myString = myInt.ToString(); string s = i.ToString(); string s = Convert.ToString(i); string s = string.Format("{0}", i); string s = $"{i}"; string s = "" + i; string s = string.Empty + i; string s = new StringBuilder().Append(i).ToString(); Just in case you want the binary representation and you're still drunk from last nights party
我如何将一个int数据类型转换为C#中的string数据类型? string myString = myInt.ToString(); string s = i.ToString(); string s = Convert.ToString(i); string s = string.Format("{0}", i); string s = $"{i}"; string s = "" + i; string s = string.Empty + i; string s = new StringBuilder().Append(i).ToString(); 以防万一你想要二进制表示,并且你仍然从昨晚聚会中喝醉了: private static string ByteToString(int
I was reading with interesting this article called C# Closures Explained, which states: You see, the C# compiler detects when a delegate forms a closure which is passed out of the current scope and it promotes the delegate, and the associated local variables into a compiler generated class. This way, it simply needs a bit of compiler trickery to pass around an instance of the compiler generate
我正在阅读有趣的这篇名为C#Closures Explained的文章,其中指出: 您会发现,C#编译器会检测代理何时形成从当前作用域传出的闭包,并将委托和关联的局部变量提升为编译器生成的类。 这样,它只需要一些编译器技巧来传递编译器生成的类的实例,所以每次我们调用委托时,我们实际上都在调用这个类的方法。 所以基本上一个封闭变量被存储为一个匿名类的成员变量,它也包含代表lambda表达式的委托或者通过变量关闭的其他代码
Today I have this repeated code: public class MyProjectionExpressions { public static Expression<Func<Log, dynamic>> LogSelector() { return log => new { logId = log.LogId, message = log.Message, }; } public static dynamic LogSelector(Log log) { return new { logId = log.LogId,
今天我有这个重复的代码: public class MyProjectionExpressions { public static Expression<Func<Log, dynamic>> LogSelector() { return log => new { logId = log.LogId, message = log.Message, }; } public static dynamic LogSelector(Log log) { return new { logId = log.LogId, mes
I'm testing performance differences using various lambda expression syntaxes. If I have a simple method: public IEnumerable<Item> GetItems(int point) { return this.items.Where(i => i.IsApplicableFor(point)); } then there's some variable lifting going on here related to point parameter because it's a free variable from lambda's perspective. If I would call this met
我使用各种lambda表达式语法测试性能差异。 如果我有一个简单的方法: public IEnumerable<Item> GetItems(int point) { return this.items.Where(i => i.IsApplicableFor(point)); } 那么这里有一些与point参数相关的变量,因为它是从lambda的角度来看的一个自由变量。 如果我将这种方法调用一百万次,最好是保持原样,还是以任何方式改变它以提高性能? 我有什么选择,哪些可行? 据我了解这是我必须摆脱
I need to convert strings to DateTime objects that are in non-English languages. I've seen many examples of converting DateTime to strings in other languages, but not the other way around. This doesn't seem to work: CultureInfo provider = new CultureInfo("ar-AE"); // Arabic - United Arab Emirates string sample = "الاربعاء 16 مارس 2011"; // Arabic date in Gregorian calendar DateTim
我需要将字符串转换为使用非英语语言的DateTime对象。 我见过很多将DateTime转换为其他语言字符串的例子,但是没有其他方法。 这似乎并不奏效: CultureInfo provider = new CultureInfo("ar-AE"); // Arabic - United Arab Emirates string sample = "الاربعاء 16 مارس 2011"; // Arabic date in Gregorian calendar DateTime result; DateTime expected = new DateTime(2011, 3, 16); // the expected date bool b;
How do I update only certain fields on an entity? I have a User entity like so: public class User { public string UserId { get; set; } public string PasswordHash { get; set; } public bool IsDisabled { get; set; } public DateTime AccessExpiryDate { get; set; } public bool MustChangePassword { get; set; } public DateTime DateCreated { get; set; } public DateTime LastA
我如何仅更新实体上的某些字段? 我有这样的用户实体: public class User { public string UserId { get; set; } public string PasswordHash { get; set; } public bool IsDisabled { get; set; } public DateTime AccessExpiryDate { get; set; } public bool MustChangePassword { get; set; } public DateTime DateCreated { get; set; } public DateTime LastActivity { get; set; } } 因
Say, I have the following conceptual model, there are strories that have tags (more than one, so it's a many-to-many relationship), plus each tag belongs to a particular category. My data comes from an external source and before inserting it I want to make sure that no duplicated tags are added. Updated code snippet: static void Main(string[] args) { Story story1 = new Story(
比方说,我有以下的概念模型,有标签的标签(多于一个,所以它是多对多的关系),加上每个标签都属于特定的类别。 我的数据来自外部来源,插入之前我想确保没有添加重复标签。 更新的代码片段: static void Main(string[] args) { Story story1 = new Story(); story1.Title = "Introducing the Entity Framework"; story1.Tags.Add(new Tag { Name = ".net", }); story1.Tags.Add(ne
I recently found some strange behaviour of delegates. It appears, that casting a delegate to some other (compatible, or even the same) breaks the equality of delegates. Suppose we have some class with method: public class Foobar { public void SomeMethod(object sender, EventArgs e); } Now let's make some delegates: var foo = new Foobar(); var first = new EventHandler(foo.SomeMethod); v
我最近发现了一些代表的奇怪行为。 看起来,将委托转换为其他委托(兼容,甚至相同)打破了代表的平等。 假设我们有一些类的方法: public class Foobar { public void SomeMethod(object sender, EventArgs e); } 现在让我们来做一些代表: var foo = new Foobar(); var first = new EventHandler(foo.SomeMethod); var second = new EventHandler(foo.SomeMethod); 当然,因为具有相同目标,方法和调用列表的代表被认
I'm working on a GUI application, which relies heavily on Action<> delegates to customize behavior of our UI tools. I'm wondering if the way we are doing this has any potential issues, eg whether the implementation keeps references to captured variables, class instances that declare the delegates etc? So let's say we have this class MapControl , which wraps a stateful GUI con
我正在开发一个GUI应用程序,它很大程度上依赖于Action<>委托来自定义UI工具的行为。 我想知道如果我们这样做有任何潜在的问题,例如实现是否保持对捕获变量的引用,声明委托等的类实例? 假设我们有这个MapControl类,它封装了一个有状态的GUI控件。 该地图具有不同类型的工具(绘图,选择等),由ITool界面表示。 您可以使用StartTool()设置工具,但一次只能有一个工具处于活动状态,所以当设置另一个工具时,前一