base-class-library

Using Microsoft.Bcl.Async with Code Analysis causes errors

ⅰ亾dé卋堺 提交于 2019-11-30 03:44:46
I'm trying to use Microsoft.Bcl.Async and Code Analysis, but when I run Code Analysis I get one or more errors. I'm using Visual Studio 2012 with Update 2. This is easy for me to reproduce: Create a new default Console App that targets .Net 4 . Right click References then select Manage NuGet Packages... Click Online and type async into the Search Online box. You should see Async for .Net Framework 4 ... . Click Install and accept all questions. Add to Main() a line that says: TaskEx.Delay(1000); and a using System.Threading.Tasks; Go to project properties, Code Analysis section and tick Enable

Meaning of confusing comment above “string.Empty” in .NET/BCL source?

痴心易碎 提交于 2019-11-30 01:23:32
I'm trying to understand why string.Empty is readonly and not a const . I saw this Post but I don't understand the comment Microsoft wrote about it. As Jon Skeet wrote in a comment "I don't know - it doesn't make much sense to me, to be honest..." Shared Source Common Language Infrastructure 2.0 Release . string.cs is in sscli20\clr\src\bcl\system\string.cs // The Empty constant holds the empty string value. //We need to call the String constructor so that the compiler doesn't mark this as a literal. //Marking this as a literal would mean that it doesn't show up as a field which we can access

What is the maximum amount of characters or length for a Directory?

浪尽此生 提交于 2019-11-29 05:30:56
What is the maximum amount of characters that a typical path can contain for a directory when using C#? For example C:\test\ has 7 characters in length , what is the maximum length? Maximum for MaxPath in CLR is 260 characters The maximum amount of characters is defined by MAX_PATH in the Win32 API library. This setting is 260 and that same setting is used, hard-coded, inside the CLR BCL. A path reaching that amount of characters is likely to cause trouble (see aside below). This maximum is the maximum for the good old FAT and FAT32. Conversely, the NTFS filesystem, used on the majority of

Using Microsoft.Bcl.Async with Code Analysis causes errors

假装没事ソ 提交于 2019-11-29 00:48:43
问题 I'm trying to use Microsoft.Bcl.Async and Code Analysis, but when I run Code Analysis I get one or more errors. I'm using Visual Studio 2012 with Update 2. This is easy for me to reproduce: Create a new default Console App that targets .Net 4 . Right click References then select Manage NuGet Packages... Click Online and type async into the Search Online box. You should see Async for .Net Framework 4 ... . Click Install and accept all questions. Add to Main() a line that says: TaskEx.Delay

Why does TimeSpan.FromSeconds(double) round to milliseconds?

隐身守侯 提交于 2019-11-28 22:31:14
TimeSpan.FromSeconds takes a double, and can represent values down to 100 nanoseconds, however this method inexplicably rounds the time to whole milliseconds. Given that I've just spent half an hour to pinpoint this (documented!) behaviour, knowing why this might be the case would make it easier to put up with the wasted time. Can anyone suggest why this seemingly counter-productive behaviour is implemented? TimeSpan.FromSeconds(0.12345678).TotalSeconds // 0.123 TimeSpan.FromTicks((long)(TimeSpan.TicksPerSecond * 0.12345678)).TotalSeconds // 0.1234567 As you've found out yourself, it's a

Bug in Directory.GetParent?

本小妞迷上赌 提交于 2019-11-28 12:02:14
I was hit in the face by a very weird behavior of the System.IO.Directory.GetParent method: string path1 = @"C:\foo\bar"; DirectoryInfo parent1 = Directory.GetParent(path1); Console.WriteLine (parent1.FullName); // Prints C:\foo, as expected // Notice the extra backslash. It should still refer to the same location, right ? string path2 = @"C:\foo\bar\"; DirectoryInfo parent2 = Directory.GetParent(path2); Console.WriteLine (parent2.FullName); // Prints C:\foo\bar !!! I would consider it a bug, but this method has been there since 1.0, so I guess it would have been detected by now. On the other

Why do the overloads of String.Format exist?

被刻印的时光 ゝ 提交于 2019-11-28 11:56:40
I was using Reflector to look at the implementation of String.Format and had always been under the impression that the overloads of String.Format that took 1, 2 & 3 arguments were optimized versions of the method that takes an object array. However, what I found was that internally they create an object array and then call a method that takes an object array. 1 arg public static string Format(string format, object arg0) { if (format == null) { throw new ArgumentNullException("format"); } return Format(null, format, new object[] { arg0 }); } 2 args public static string Format(string format,

Why is there no SortedList<T> in .NET? [closed]

折月煮酒 提交于 2019-11-28 09:38:16
Why is there only a SortedList<TKey, TValue> which looks more like a dictionary, but no SortedList<T> that is actually just a list that is always sorted? According to the MSDN documentation on SortedList , it is actually internally implemented as a dynamically-sized array of KeyValuePair<TKey, TValue> that is always sorted by the key. Wouldn’t the same class be more useful as a list of any type T ? Wouldn’t that fit the name better, too? Although nobody can really tell you why there is no SortedList<T> , it is possible to discuss why SortedList takes a key and a value. A dictionary maps keys

How to create multiple directories from a single full path in C#?

被刻印的时光 ゝ 提交于 2019-11-28 03:37:12
If you have a full path like: "C:\dir0\dir1\dir2\dir3\dir4\" how would you best implement it so that all directories are present? Is there a method for this in the BCL? If not, what's the most elegant way to do this? I would call Directory.CreateDirectory(@"C:\dir0\dir1\dir2\dir3\dir4\") . Contrary to popular belief, Directory.CreateDirectory will automatically create whichever parent directories do not exist. In MSDN's words, Creates all directories and subdirectories as specified by path. If the entire path already exists, it will do nothing. (It won't throw an exception) Create directories

Efficient, Immutable, Extensible Collections for .NET [duplicate]

橙三吉。 提交于 2019-11-27 22:56:12
This question already has an answer here: Immutable collections? 10 answers It seems to me there is an extreme lack of safe, immutable collection types for .NET, in particular BCL but I've not seen much work done outside either. Do anyone have any pointers to a (preferably) production quality, fast, immutable collections library for .NET. A fast list type is essential. I'm not yet prepared to switch to F#. *Edit: Note to searchers, this is being rolled into the BCL soon: .NET immutable collections You might want to take a look at the Microsoft.FSharp.Collections namespace in the FSharp.Core