enumeration

Why is the enumeration value from a multi dimensional array not equal to itself?

烈酒焚心 提交于 2019-12-02 16:01:52
Consider: using System; public class Test { enum State : sbyte { OK = 0, BUG = -1 } static void Main(string[] args) { var s = new State[1, 1]; s[0, 0] = State.BUG; State a = s[0, 0]; Console.WriteLine(a == s[0, 0]); // False } } How can this be explained? It occurs in debug builds in Visual Studio 2015 when running in the x86 JIT. A release build or running in the x64 JIT prints True as expected. To reproduce from the command line: csc Test.cs /platform:x86 /debug ( /debug:pdbonly , /debug:portable and /debug:full also reproduce.) You found a code generation bug in the .NET 4 x86 jitter. It is

C# - Playing random sound files from folder [closed]

廉价感情. 提交于 2019-12-02 12:29:45
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . I'm attempting to create an Oracle (read: Magic 8 Ball). The idea behind it is that on each button press, a sound file with wise words is played (picked at random). I have it working using switches, however I'm searching for a way to make it more.. logical. This is how it currently looks, with the

Deleting registry key values

巧了我就是萌 提交于 2019-12-02 08:43:54
In MSDN it says that RegEnumValue should not be used when calling function that change the registry keys being enumerated. So does this also apply to deleting registry key values? Like this code does: if (RegOpenKeyEx(m_hkey,m_path.c_str(),0,KEY_ALL_ACCESS,&key) == ERROR_SUCCESS) { bool error=false; idx=0; while (RegEnumValue(key,idx,name,&namesize,NULL,NULL,NULL,NULL) == ERROR_SUCCESS && !error) { error=(RegDeleteValue(key,name)!=ERROR_SUCCESS); idx++; } RegCloseKey(key); } Your code does not work. When you delete index 0, the next item becomes index 0, and you do not delete that. So yes, it

for-in loop VS in-operator

一曲冷凌霜 提交于 2019-12-02 07:21:48
问题 I consider myself a JS veteran but just now for the first time I have realised that the for ... in loop does something very different from the in operator: "length" in []; // true for (k in []) { if(k == "length") alert(); }; // k will never be "length" So this brings me to my question: why is the in operator at all present in the for ... in loop? Imho it is totally misleading, as it does different things. Also the notion that first the for operation makes the JS engine take all enumerable

for-in loop VS in-operator

删除回忆录丶 提交于 2019-12-02 06:31:51
I consider myself a JS veteran but just now for the first time I have realised that the for ... in loop does something very different from the in operator: "length" in []; // true for (k in []) { if(k == "length") alert(); }; // k will never be "length" So this brings me to my question: why is the in operator at all present in the for ... in loop? Imho it is totally misleading, as it does different things. Also the notion that first the for operation makes the JS engine take all enumerable properties and then on that subset the in operator is used is imho wrong: simply because the in operator

Switch statement for imported NS_OPTIONS (RawOptionSetType) in Swift?

我的梦境 提交于 2019-12-02 06:09:44
问题 The switch statement in Swift is so much more expressive. I'm wondering if this might be possible: Lets look at UIViewAutoresizing for example. It's defined in Objective-C as follows: typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) { UIViewAutoresizingNone = 0, UIViewAutoresizingFlexibleLeftMargin = 1 << 0, UIViewAutoresizingFlexibleWidth = 1 << 1, UIViewAutoresizingFlexibleRightMargin = 1 << 2, UIViewAutoresizingFlexibleTopMargin = 1 << 3, UIViewAutoresizingFlexibleHeight = 1 << 4,

How to translate a Java Enumeration to C#?

最后都变了- 提交于 2019-12-02 04:59:04
问题 I have some Java code and I would like to translate it to C#. srcParams is a Hashtable. This is the Java code: for (Enumeration keys = srcParams.keys(); keys.hasMoreElements()) { key = keys.nextElement(); destParams.Add(key, srcParams[key]); } And this is my attempt in C# IEnumerator key = srcParams.Keys.GetEnumerator(); while (key.MoveNext()) { destParams.Add(key, srcParams[key]); } Could you tell me if it's correct? 回答1: foreach(var key in srcParams.Keys) { destParams.Add(key, srcParams[key

Counting the distinct elements in an array

泄露秘密 提交于 2019-12-02 02:33:26
问题 I have an array: a = [1, 2, 3, 3, 6, 8, 1, 9] I want to display each unique element value and its associated element count like this: 1: 2 2: 1 3: 2 6: 1 8: 1 9: 1 So far I have: a.sort.group_by { |x| x } { 1 => [ [0] 1, [1] 1 ], 2 => [ [0] 2 ], 3 => [ [0] 3, [1] 3 ], 6 => [ [0] 6 ], 8 => [ [0] 8 ], 9 => [ [0] 9 ] } So each element of the Hash contains an array. I can use that array's count to get my answer, but I'm having trouble figuring out how to process the hash concisely. Is this a

Why is list.remove only removing every second item?

妖精的绣舞 提交于 2019-12-02 01:54:10
In my Python 2.7.2 IDLE interpreter: >>> mylist = [1, 2, 3, 4, 5] >>> for item in mylist: mylist.remove(item) >>> mylist [2, 4] Why? It's because when you iterate over a list, python keeps track of the index in the list . Consider the following code instead: for i in range(len(mylist)): if i >= len(mylist): break item = mylist[i] mylist.remove(item) If we track this (which is essentially what python is doing in your code), then we see that when we remove an item in the list, the number to the right shifts one position to the left to fill the void left when we removed the item. The right item

Counting the distinct elements in an array

不羁岁月 提交于 2019-12-02 00:25:53
I have an array: a = [1, 2, 3, 3, 6, 8, 1, 9] I want to display each unique element value and its associated element count like this: 1: 2 2: 1 3: 2 6: 1 8: 1 9: 1 So far I have: a.sort.group_by { |x| x } { 1 => [ [0] 1, [1] 1 ], 2 => [ [0] 2 ], 3 => [ [0] 3, [1] 3 ], 6 => [ [0] 6 ], 8 => [ [0] 8 ], 9 => [ [0] 9 ] } So each element of the Hash contains an array. I can use that array's count to get my answer, but I'm having trouble figuring out how to process the hash concisely. Is this a horrible implementation? a.sort.group_by { |x| x }.each {|x| puts "#{x[0]} #{x[1].count}" } How about: a