base-class-library

Is iterating over a Queue<T> guaranteed to be in queue order?

非 Y 不嫁゛ 提交于 2019-12-07 12:58:03
问题 Is this guaranteed to always print 123 ? Queue<string> theQueue = new Queue<string>(); theQueue.Enqueue("1"); theQueue.Enqueue("2"); theQueue.Enqueue("3"); foreach(var str in theQueue) { Console.Write(str); } Console.WriteLine(); Edit: I totally agree that a queue that enumerated in any other order would be obviously incorrect. That's why I asked the question. However, the abstract data type queue only makes guarantees about its enqueue and dequeue operations. I'm looking for an answer that

Why can't I use await keyword in my Windows Phone 7.1 MvvmCross project while using the Microsoft.Bcl - cannot await 'System.Threading.Tasks.Task?

老子叫甜甜 提交于 2019-12-07 10:21:18
问题 I am unable to use the await keyword in my MvvmCross Windows Phone 7.1 project while using the Microsoft.Bcl "Microsoft BCL Portability Pack". I have posted the code for the sample project that I describe below on GitHub and the await error occurs on this line. When I try to build the third "Core" Windows Portable Class Library (PCL) that contains the FirstViewModel, I get the errors of: Type System.Threading.Tasks.Task<string> not awaitable under VS red squiggles, and Cannot await 'System

ImmutableArray<> behaves differently than Array<> for nested Select with index

对着背影说爱祢 提交于 2019-12-07 04:45:16
问题 I am encountering what seems to be a very weird bug in ImmutableArray<> (with BCL Immutable collections v1.0.12.0, runtime .NET 4.5): I have the following two identical structs exactly in the same source file under the same namespace: public struct WeightedComponent { public readonly IComponent Component; public readonly decimal Weight; public WeightedComponent(IComponent component, decimal weight) { this.Component = component; this.Weight = weight; } } public struct WeightedComponent2 {

Can a byte[] buffer for a MemoryStream have variable size?

假如想象 提交于 2019-12-06 10:05:01
I'm serializing an object to a byte[] using MemoryStream : byte[] serialized = new byte[1000]; using (MemoryStream stream = new MemoryStream(serialized)) using (TextWriter textWriter = new StreamWriter(stream)) serializer.Serialize(textWriter, stuffToSerialize); is there any way I can set 'serialized' to grow according to the size of the stuffToSerialize ? The parameterless constructor new MemoryStream() uses one. Then serialise into it, and then when you need the byte[] call ToArray() which creates a copy of whatever length of the buffer was actually used (the internal buffer will generally

Linq's Enumerable.Count method checks for ICollection<> but not for IReadOnlyCollection<>

我只是一个虾纸丫 提交于 2019-12-06 04:58:00
Background: Linq-To-Objects has the extension method Count() (the overload not taking a predicate). Of course sometimes when a method requires only an IEnumerable<out T> (to do Linq), we will really pass a "richer" object to it, such as an ICollection<T> . In that situation it would be wasteful to actually iterate through the entire collection (i.e. get the enumerator and "move next" a whole bunch of times) to determine the count, for there is a property ICollection<T>.Count for this purpose. And this "shortcut" has been used in the BCL since the beginning of Linq. Now, since .NET 4.5 (of 2012

Is iterating over a Queue<T> guaranteed to be in queue order?

心不动则不痛 提交于 2019-12-05 21:59:01
Is this guaranteed to always print 123 ? Queue<string> theQueue = new Queue<string>(); theQueue.Enqueue("1"); theQueue.Enqueue("2"); theQueue.Enqueue("3"); foreach(var str in theQueue) { Console.Write(str); } Console.WriteLine(); Edit: I totally agree that a queue that enumerated in any other order would be obviously incorrect. That's why I asked the question. However, the abstract data type queue only makes guarantees about its enqueue and dequeue operations. I'm looking for an answer that references documentation that guarantees this ordering in the .NET BCL. Yes. It is. A queue is a first

Why can't I use await keyword in my Windows Phone 7.1 MvvmCross project while using the Microsoft.Bcl - cannot await 'System.Threading.Tasks.Task?

吃可爱长大的小学妹 提交于 2019-12-05 18:17:11
I am unable to use the await keyword in my MvvmCross Windows Phone 7.1 project while using the Microsoft.Bcl "Microsoft BCL Portability Pack". I have posted the code for the sample project that I describe below on GitHub and the await error occurs on this line . When I try to build the third "Core" Windows Portable Class Library (PCL) that contains the FirstViewModel, I get the errors of: Type System.Threading.Tasks.Task<string> not awaitable under VS red squiggles, and Cannot await 'System.Threading.Tasks.Task<string>' when building. There are four projects in the solution: A Windows Portable

What does RuntimeHelpers.GetHashCode do

一曲冷凌霜 提交于 2019-12-05 09:39:23
问题 The RuntimeHelpers.GetHashCode(object) method allows generating hash codes based on the identity of an object. MSDN states: The RuntimeHelpers.GetHashCode method always calls the Object.GetHashCode method non-virtually, even if the object's type has overridden the Object.GetHashCode method. [MethodImpl(MethodImplOptions.InternalCall)] [SecuritySafeCritical] public static extern int GetHashCode(object o); However, when inspecting the Object.GetHashCode() method using Reflector (.NET 4.0), we

When should I use a BitVector32?

左心房为你撑大大i 提交于 2019-12-05 08:26:08
I am working on a project where at a certain moment I need to show for one month which days are still available. There is a function that calculates which days are available. My colleagues said:"Oh we know, you should return a BitVector32 . That's the most efficient when working with a list of booleans." I would have used a List<bool> or something like that. A BitVector32 seems to me to be something for low level stuff when you are actually working with bits. So, the question is. Should you use the BitVector32 whenever you need some list of booleans with less than 32 items or should you only

ImmutableArray<> behaves differently than Array<> for nested Select with index

霸气de小男生 提交于 2019-12-05 08:17:37
I am encountering what seems to be a very weird bug in ImmutableArray<> (with BCL Immutable collections v1.0.12.0, runtime .NET 4.5): I have the following two identical structs exactly in the same source file under the same namespace: public struct WeightedComponent { public readonly IComponent Component; public readonly decimal Weight; public WeightedComponent(IComponent component, decimal weight) { this.Component = component; this.Weight = weight; } } public struct WeightedComponent2 { public readonly IComponent Component; public readonly decimal Weight; public WeightedComponent2(IComponent