base-class-library

How can I convert BitArray to single int?

大憨熊 提交于 2019-12-17 04:29:42
问题 How can I convert BitArray to a single int ? 回答1: private int getIntFromBitArray(BitArray bitArray) { if (bitArray.Length > 32) throw new ArgumentException("Argument length shall be at most 32 bits."); int[] array = new int[1]; bitArray.CopyTo(array, 0); return array[0]; } 回答2: private int getIntFromBitArray(BitArray bitArray) { int value = 0; for (int i = 0; i < bitArray.Count; i++) { if (bitArray[i]) value += Convert.ToInt16(Math.Pow(2, i)); } return value; } 回答3: This version: works for up

Xamarin.Mac 4.5 with BCL Async release compile fails to resolve System.Threading.Tasks

℡╲_俬逩灬. 提交于 2019-12-13 18:03:34
问题 I have been using .NET 4.5 in Xamarin Studio with portable libraries and a Xamarin.Mac project. When the Xamarin.Mac project is set to .NET 4.5 and Microsoft Async is added via nuget, compile in Debug will succeed but Release/AppStore will fail with error MM2002: Failed to resolve assembly: 'System.Threading.Tasks, In this case, it is unnecessary to add the dlls (System.Threading.Tasks and System.Runtime) from BCL because they are already in .NET 4.5. If you switch to .NET 4.0 it will work,

Is Environment.TickCount affected by system time adjustments?

妖精的绣舞 提交于 2019-12-12 15:51:31
问题 I'm curious as to how the .NET BCL property Environment.TickCount is implemented. In particular I'd like to now if it is affected by system time adjustments. My first guess as to how the property was implemented was that it was simply a managed wrapper around the GetTickCount method. However, the documentation for the GetTickCount method states that it is affected by adjustments made by the GetSystemTimeAdjustment function but the documentation for Environment.TickCount does not mention

Go To Statement Considered Harmful?

雨燕双飞 提交于 2019-12-12 09:30:48
问题 If the statement above is correct, then why when I use reflector on .Net BCL I see it is used a lot? EDIT: let me rephrase: are all the GO-TO's I see in reflector written by humans or compilers? 回答1: The above isn't really correct - it was a polemical device used by Dijkstra at a time when gotos were about the only flow control structure in use. In fact, several people have produced rebuttals, including Knuth's classic "Structured Programming Using Goto" paper (title from memory). And there

How to find out a list of types in Base Class Library that implement specific interface?

杀马特。学长 韩版系。学妹 提交于 2019-12-10 21:00:06
问题 Sometimes I want to find out a list of all standard .NET types that implement a specific interface. Usually it is out of curiosity, sometimes there is also some practical purpose (but that's not the point). I tried to get this out of MSDN, but type's page only contains links children of types, not types implementing interface. Do you know any trick how to do this (or a tool that would help)? I wrote this code ( ICollection is the type being investigated): var result = from assembly in

Nullable<> types are a BCL, CLR, or both implementation?

我怕爱的太早我们不能终老 提交于 2019-12-10 17:55:49
问题 Some time ago I thought that Nullable<> value types are classes, encapsulating value types and a bool to HasValue. With some implicit cast operador for null, just implemented at BCL. But being a struct, how this can be achieved? Nullable<> struct is "special" for CLR? 回答1: Nullable<T> is defined as a normal struct, but there's special hooks within the CLR to box/unbox an instance of [mscorlib]System.Nullable`1 to null according to the HasValue property. There's more details on this here 回答2:

.NET TcpClient/NetworkStream implementation that supports async operations and respects timeouts

孤者浪人 提交于 2019-12-10 05:16:25
问题 Based on the number of questions, forum posts, etc, it appears that the TcpClient/NetworkStream implementation in the BCL lacks decent support for cancelling IO operations. With the addition of Async methods in .NET 4.5, this lack of cancellation (or decent timeout support) makes things even more frustrating since it becomes even more complicated (nigh on impossible) to cancel a task that refuses to monitor its CancellationToken while performing IO. I have seen many implementations that spin

F# structural tuples versus BCL Tuple types

微笑、不失礼 提交于 2019-12-08 18:35:08
问题 In F# you can define a first function as follows: let first (x, y) = x You can call it like this: first (1, 2) You can also define the same function in terms of the BCL Tuple type: let first (t:Tuple<_, _ >) = t.Item1 However, you cannot call it using the prior syntax, or you will get the following error: error FS0001: The type ''c * 'd' is not compatible with the type 'Tuple<'a,'b>' Instead, you have to do the following: first (Tuple<_,_>(1, 2)) This is strange, since compiled F# code does

Microsoft.Threading.Tasks referencing an incorrect System.Threading.Tasks.dll version

懵懂的女人 提交于 2019-12-07 22:26:02
问题 I'm developing a C# library with .NET framework 4.0. On this library I have these NuGet packages installed: <?xml version="1.0" encoding="utf-8"?> <packages> <package id="Microsoft.Bcl" version="1.1.10" targetFramework="net40" /> <package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net40" /> <package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net40" /> <package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net40" /> <package id="Newtonsoft.Json"

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

ぐ巨炮叔叔 提交于 2019-12-07 18:52: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.