clr

String sorting performance degradation in VS2010 vs. VS2008

試著忘記壹切 提交于 2019-11-27 03:11:05
问题 The following C# code seems to run slower when built with VS2010 than with VS2008: on a Core i5 Win7 x64 8 GB RAM PC, the VS2008 built version sorts strings in about 7.5 seconds, instead the VS2010 built version requires about 9 seconds. Why is that? Is there anything wrong with my code? Did the sorting algorithm change in VS2010? Is there anything different in the underlying CLR that makes the performance worse? using System; using System.Collections.Generic; using System.Diagnostics; using

What is the maximum number of parameters that a C# method can be defined as taking?

不羁岁月 提交于 2019-11-27 03:02:08
问题 I am trying to figure out what the maximum number of parameters a method in C# can have. I've checked everywhere for an answer, including the C# official documentation, MSDN, and a couple of CLR references and I can't find an answer. Does anyone have an answer to this question? 回答1: Here is your theoretical answer: In order to push method arguments onto the stack, compiled code has the following MSIL opcodes to choose from: ldarg.0 ldarg.1 ldarg.2 ldarg.3 ldarg.S ldarg ldarg.0 to ldarg.3 is

Func<> with unknown number of parameters

拈花ヽ惹草 提交于 2019-11-27 02:46:35
问题 Consider the following pseudo code: TResult Foo<TResult>(Func<T1, T2,...,Tn, TResult> f, params object[] args) { TResult result = f(args); return result; } The function accepts Func<> with unknown number of generic parameters and a list of the corresponding arguments. Is it possible to write it in C#? How to define and call Foo ? How do I pass args to f ? 回答1: That's not possible. At best, you could have a delegate that also takes a variable number of arguments, and then have the delegate

CLR SQL Assembly: Get the Bytestream?

烈酒焚心 提交于 2019-11-27 02:45:08
问题 I have a SQL CLR dll I want to deploy, but have found you can embed the byte stream/varbinary_literal/ varbinary_expression/assembly bits into a text file to get around the messy hassle of packaging a DLL and making sure it's accessible for the CREATE ASSEMBLY command. But what I have yet to find is how to get that byte stream/varbinary_literal/ varbinary_expression/assembly bits value. I haven't found any consistent terminology, and what I keep finding in using Load() . 回答1: It's just a hex

What is the overhead of C# fixed statement on a managed unsafe struct containing fixed arrays?

我与影子孤独终老i 提交于 2019-11-27 02:14:28
问题 I've been trying to determine what the true cost of using the fixed statement within C# for managed unsafe structs that contain fixed arrays. Please note I am not referring to unmanaged structs. Specifically, is there any reason to avoid the pattern shown by 'MultipleFixed' class below? Is the cost of simply fixing the data non zero, near zero (== cost similar to setting & clearing a single flag when entering/exiting the fixed scope), or is it significant enough to avoid when possible?

Assert.AreEqual() with System.Double getting really confusing

时光毁灭记忆、已成空白 提交于 2019-11-27 02:13:57
问题 Description This is not a real world example! Please don't suggest using decimal or something else. I am only asking this because I really want to know why this happens. I recently saw the awesome Tekpub Webcast Mastering C# 4.0 with Jon Skeet again. On episode 7 - Decimals and Floating Points it is going really weird and even our Chuck Norris of Programming (aka Jon Skeet) does not have a real answer to my question. Only a might be . Question: Why did MyTestMethod() fail and MyTestMethod2()

What's the magic of arrays in C#

↘锁芯ラ 提交于 2019-11-27 02:13:26
问题 int[] a = new int[5]; string[] b = new string[1]; The types of both a and b inherit from the abstract System.Array , but there is no real classes in the built-in library(it seems that there are some runtime types, you can't find the type defination class of an int[] ). Can you tell me what happens while compiling? And why did they(the c# team) make this design(I mean why it's not something like Array<T> ,instead they are using an abstract class with compiler magics)? 回答1: Trying to reason

CLR System.NullReferenceException when forcing 'Set Next Statement' into 'if' block

我是研究僧i 提交于 2019-11-27 02:11:12
问题 Background I accept this isn't something that can occur during normal code execution but I discovered it while debugging and thought it interesting to share. I think this is caused by the JIT compiler, but would welcome any further thoughts. I have replicated this issue targeting the 4.5 and 4.5.1 framework using VS2013: Setup To see this exception Common Language Runtime Exceptions must be enabled: DEBUG > Exceptions... I have distilled the cause of the issue to the following example: using

How to force an application to use .NET 3.5 or above?

ぐ巨炮叔叔 提交于 2019-11-27 01:53:27
问题 Our application is built with VS 2008, uses Linq and has Target Framework set to .NET Framework3.5. It works OK when only .NET 3.5 or 4 is installed on the machine. However, on machines where both .NET 2 (or 3.0) and .NET 4 are installed, the application is loaded with .NET 2, and crashes when Linq is accessed, as it looks for the .NET 3.5 libraries. Using the tag in app.config doesn't seem to help, as it specifies the CLR version, which is 2 in case of .NET 3.5. Note that our installation

Why does Random.Next() always return the same number [duplicate]

社会主义新天地 提交于 2019-11-27 01:44:50
This question already has an answer here: Random number generator only generating one random number 9 answers Consider this method: private static int GenerateRandomNumber(int seed, int max) { return new Random(seed).Next(max); } On my machine, executing this loop yields the same number through 1500 iterations: for (int i = 0; i < 1501; i++) { int random = GenerateRandomNumber(100000000, 999999999); Console.WriteLine(random.ToString()); Console.ReadKey(); } I get 145156561, for every single iteration. I don't have a pressing issue, I was just curious about this behavior because .Next(max) says