.net

Enumerator.MoveNext() throws 'Collection was Modified' on first call

坚强是说给别人听的谎言 提交于 2021-02-16 13:33:22
问题 Consider the following code: List<int> list = new List<int>(); IEnumerable<int> enumerable = list; IEnumerator<int> enumerator = enumerable.GetEnumerator(); list.Add(1); bool any = enumerator.MoveNext(); At runtime, the last line throws an: InvalidOperationException: Collection was modified; enumeration operation may not execute. I understand the need for IEnumerators to throw 'Collection was modified' exceptions when the IEnumerable changes, but I don't understand this: Why does the

RegEx to match a pattern, as long as it is not preceded by a different pattern

送分小仙女□ 提交于 2021-02-16 10:24:27
问题 I need a regex that is to be used for text substitution. Example: text to be matched is ABC (which could be surrounded by square brackets), substitution text is DEF . This is basic enough. The complication is that I don't want to match the ABC text when it is preceded by the pattern \[[\d ]+\]\. - in other words, when it is preceded by a word or set of words in brackets, followed by a period. Here are some examples of source text to be matched, and the result, after the regex substitution

RegEx to match a pattern, as long as it is not preceded by a different pattern

核能气质少年 提交于 2021-02-16 10:24:26
问题 I need a regex that is to be used for text substitution. Example: text to be matched is ABC (which could be surrounded by square brackets), substitution text is DEF . This is basic enough. The complication is that I don't want to match the ABC text when it is preceded by the pattern \[[\d ]+\]\. - in other words, when it is preceded by a word or set of words in brackets, followed by a period. Here are some examples of source text to be matched, and the result, after the regex substitution

Placeholder in TextBox in Window Forms using VB.NET [duplicate]

强颜欢笑 提交于 2021-02-16 09:16:03
问题 This question already has answers here : Watermark TextBox in WinForms (10 answers) Closed 2 years ago . I'm working on a Windows Forms application in VB.NET and I am currently making a login screen using labels and TextBoxes. What I need is the Placeholder in TextBox controls you can see below ↓ (not mine obviously) Is there any property in TextBox that allows me to set the default placeholder (placeholder, watermark, hint, tip) to what I want it to be? If there is not any, how can i solve

Placeholder in TextBox in Window Forms using VB.NET [duplicate]

牧云@^-^@ 提交于 2021-02-16 09:15:42
问题 This question already has answers here : Watermark TextBox in WinForms (10 answers) Closed 2 years ago . I'm working on a Windows Forms application in VB.NET and I am currently making a login screen using labels and TextBoxes. What I need is the Placeholder in TextBox controls you can see below ↓ (not mine obviously) Is there any property in TextBox that allows me to set the default placeholder (placeholder, watermark, hint, tip) to what I want it to be? If there is not any, how can i solve

Placeholder in TextBox in Window Forms using VB.NET [duplicate]

两盒软妹~` 提交于 2021-02-16 09:13:14
问题 This question already has answers here : Watermark TextBox in WinForms (10 answers) Closed 2 years ago . I'm working on a Windows Forms application in VB.NET and I am currently making a login screen using labels and TextBoxes. What I need is the Placeholder in TextBox controls you can see below ↓ (not mine obviously) Is there any property in TextBox that allows me to set the default placeholder (placeholder, watermark, hint, tip) to what I want it to be? If there is not any, how can i solve

Regex to match everything except a list of characters

我与影子孤独终老i 提交于 2021-02-16 08:59:09
问题 I want to match a line containing everything except the specified characters [I|V|X|M|C|D|L] . new Regex(@"^(.*) is (?![I|V|X|M|C|D|L].*)$") should match everything except the characters mentioned in the OR list. Should match - name is a Should not match - edition is I 回答1: Try this pattern: ^[^IVXMCDL]*$ This will match the start of the string, followed by zero or more characters other than those specified in the character class, followed by the end of the string. In other words, it will not

How do you pass parameters by ref when calling a static method using reflection?

允我心安 提交于 2021-02-16 06:06:26
问题 I'm calling a static method on an object using reflection: MyType.GetMethod("MyMethod", BindingFlags.Static).Invoke(null, new object[] { Parameter1, Parameter2 }); How do you pass parameters by ref, rather that by value? I assume they would be by value by default. The first parameter ("Parameter1" in the array) should be by ref, but I can't figure out how to pass it that way. 回答1: For a reference parameter (or out in C#), reflection will copy the new value into the object array at the same

How do you pass parameters by ref when calling a static method using reflection?

馋奶兔 提交于 2021-02-16 06:05:44
问题 I'm calling a static method on an object using reflection: MyType.GetMethod("MyMethod", BindingFlags.Static).Invoke(null, new object[] { Parameter1, Parameter2 }); How do you pass parameters by ref, rather that by value? I assume they would be by value by default. The first parameter ("Parameter1" in the array) should be by ref, but I can't figure out how to pass it that way. 回答1: For a reference parameter (or out in C#), reflection will copy the new value into the object array at the same

Using Interlocked.CompareExchange with a class

半世苍凉 提交于 2021-02-16 04:32:50
问题 System.Threading.Interlocked.CompareExchange operator provides atomic (thus thread-safe) C# implementation of the Compare-And-Swap operation. For example int i = 5; Interlocked.CompareExchange(ref i, 10, 5); After this command, the int i would have a value = 10. And also the compare and exchange happens atomically (single operation). When I tried using this with a class instance, the compare fails and the values are not exchanged. public class X { public int y; public X(int val) { y = val; }