clr

String interning?

我的梦境 提交于 2019-11-29 02:23:24
The second ReferenceEquals call returns false. Why isn't the string in s4 interned? (I don't care about the advantages of StringBuilder over string concatenation.) string s1 = "tom"; string s2 = "tom"; Console.Write(object.ReferenceEquals(s2, s1)); //true string s3 = "tom"; string s4 = "to"; s4 += "m"; Console.Write(object.ReferenceEquals(s3, s4)); //false When I do String.Intern(s4); , I still get false. Here, both s3 and s4 are interned but their references are not equal? string s3 = "tom"; string s4 = "to"; s4 += "m"; String.Intern(s4); Console.WriteLine(s3 == s4); //true Console.WriteLine

Accuracy of Math.Sin() and Math.Cos() in C#

ε祈祈猫儿з 提交于 2019-11-29 02:23:16
I am terribly annoyed by the inaccuracy of the intrinsic trig functions in the CLR. It is well know that Math.Sin(Math.PI)=0.00000000000000012246063538223773 instead of 0. Something similar happens with Math.Cos(Math.PI/2) . But when I am doing a long series of calculations that on special cases evaluate to Math.Sin(Math.PI/2+x)-Math.Cos(x) and the result is zero for x=0.2, but not zero for x=0.1 (try it). Another issue is when the argument is a large number, the inaccuracy gets proportionally large. So I wonder if anyone has coded some better representation of the trig functions in C# for

Strange casting behaviour. Cannot cast object (int) to long

自古美人都是妖i 提交于 2019-11-29 02:06:48
问题 I have the following code: int intNumber1 = 100; object intNumber2 = 100; bool areNumberOfTheSameType = intNumber1.GetType() == intNumber2.GetType(); // TRUE bool areEqual = intNumber1.Equals(intNumber2); // TRUE long longNumber1 = (long) intNumber1; // OK long longNumber2 = (long) intNumber2; // InvalidCastException. Why? Why doesn't the second cast work? I realize that it might be because the object doesn’t have an explicit cast to a long, but if we look at its type on runtime it is System

C# StructLayout.Explicit Question

北慕城南 提交于 2019-11-29 01:58:56
I'm trying to understand why the second example below works with no issues, but the first example gives me the exception below. It seems to me that both examples should give an exception based on the description. Can anyone enlighten me? Unhandled Exception: System.TypeLoadException: Could not load type 'StructTest.OuterType' from assembly 'StructTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because it contains an object field at offset 0 that is incorrectly aligned or overlapped by a non-object field. at StructTest.Program.Main(String[] args) Press any key to continue . . .

When linking a .NET 2.0 Managed Assembly from a .NET 4.0 Application, which framework is used?

跟風遠走 提交于 2019-11-29 01:53:55
问题 If I have a 2.0 CLR assembly (pure managed code, no mixed mode issues) that I need to link to from a 4.0 CLR Application, does the 2.0 code run on the 2.0 CLR or 4.0. Basically, is there any risk of 4.0 breaking changes affecting the 2.0 code? 回答1: The answer above is incorrect. You do get side by side with the full frameworks. A .Net 2 APPLICATION (note that means EXE, not library) will not auto promote to .Net 4. But if a .Net 4 application loads a .Net 2 assembly it is loaded into the same

Signing .NET assemblies: Does this protect my assembly from tampering really?

耗尽温柔 提交于 2019-11-29 01:34:00
I am implementing a "locking" system in my app which protects my app against being copied and used illegally. The system checks the signature of a hardware-based code and expects it to be signed with a Private Key that only my company owns. (The app has got the Public Key to validate the signature.) I want to make sure that no one changes my locking mechanism in the app, so I want to sign my app's assembly and I think it makes sense. Since I haven't seen the CLR ever talk about an assembly's signature being invalid, I want to make sure this system really works. Does it? What should I do to

Advantage of SQL SERVER CLR

前提是你 提交于 2019-11-28 23:37:20
What advantages does SQLServer CLR offer over T-SQL? Is using .NET syntax easier than T-SQL? I see that you can define user types, but I'm not quite clear on why that's better. For example, you could define an email type and it would have a prefix property and a domain property. You could then search on domain or prefix or both. However, I don't see how that's any different from adding a couple of columns one called prefix and one called domain and searching on them individually. Maybe someone has real world reasons why this is better. I'll give one good example: CLR has a built in RegEx

Where does .NET place the String value?

随声附和 提交于 2019-11-28 23:27:44
I am using SOS debug extension dll to check the memory layout of a String type. And below is the result. !dso ESP/REG Object Name 0015EFC0 01c6b9cc System.String hello,world !do 01c6b9cc Name: System.String MethodTable: 6de3f9ac EEClass: 6db78bb0 Size: 36(0x24) bytes File: C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089>\mscorlib.dll String: hello,world Fields: MT Field Offset Type VT Attr Value Name 6de42978 40000ed 4 System.Int32 1 instance 11 m_stringLength 6de41dc8 40000ee 8 System.Char 1 instance 68 m_firstChar 6de3f9ac 40000ef 8 System.String 0 shared

.NET Parameter passing - by reference v/s by value

江枫思渺然 提交于 2019-11-28 23:17:19
I'm trying to validate my understanding of how C#/.NET/CLR treats value types and reference types. I've read so many contradicting explanations I stil This is what I understand today, please correct me if my assumptions are wrong. Value types such as int etc live on the stack, Reference types live on the managed heap however if a reference type has for example has an instance variable of type double, it will live along with its object on the heap The second part is what I am most confused about. Lets consider a simple class called Person. Person has a property called Name. Lets say I create an

What does 'Cor' stand for?

白昼怎懂夜的黑 提交于 2019-11-28 23:12:05
问题 I've seen in it in the primary CLR dll, mscorlib.dll, and I've seen in it in this CLR Profiling API interface, ICorProfilerCallback2. Just curious: what does the word 'Cor' stand for? 回答1: "Common Object Runtime" For more, see: http://www.danielmoth.com/Blog/2005/05/mscorlibdll.html cor: Before .NET was chosen as the name, this new platform was a successor to COM so it was codenamed COM 3.0 and then the name chosen was… Common Object Runtime (cor) and that is where mscorlib derives its name