36
votes
5answers
17k views

Is it possible to dynamically compile and execute C# code fragments?

I was wondering if it is possible to save C# code fragments to a text file (or any input stream), and then execute those dynamically? Assuming what is provided to me would compile fine within any ...
95
votes
4answers
8k views

How does the C# compiler detect COM types?

EDIT: I've written the results up as a blog post. The C# compiler treats COM types somewhat magically. For instance, this statement looks normal... Word.Application app = new Word.Application(); ...
62
votes
1answer
4k views

Where to learn about VS debugger 'magic names'

If you've ever used Reflector, you probably noticed that the C# compiler generates types, methods, fields, and local variables, that deserve 'special' display by the debugger. For instance, local ...
18
votes
8answers
3k views

JIT compiler vs offline compilers

Are there scenarios where JIT compiler is faster than other compilers like C++? Do you think in the future JIT compiler will just see minor optimizations, features but follow a similar performance, ...
8
votes
2answers
3k views

Mono Compiler as a Service (MCS)

I'd like to consume Mono's compiler as a service from my regular .NET 3.5 application. I've downloaded the latest bits (2.6.7), created a simple console application in Visual Studio and referenced ...
18
votes
5answers
2k views

Why is the C# compiler emitting a callvirt instruction for a GetType() method call?

I am curious to know why this is happening. Please read the code example below and the corresponding IL that was emitted in comments below each section: using System; class Program { static ...
24
votes
2answers
1k views

C# compiler bug? Why doesn't this implicit user-defined conversion compile?

Given the following struct: public struct Foo<T> { public Foo(T obj) { } public static implicit operator Foo<T>(T input) { return new Foo<T>(input); } } This ...
9
votes
3answers
1k views

Why and how does C# allow accessing private variables outside the class itself when it's within the same containing class?

I don't know if the question is descriptive enough but why and how does this behaviour exist?: public class Layer { public string Name { get; set; } private IEnumerable<Layer> ...
11
votes
9answers
633 views

variable scope in statement blocks

for (int i = 0; i < 10; i++) { Foo(); } int i = 10; // error, 'i' already exists ---------------------------------------- for (int i = 0; i < 10; i++) { Foo(); } i = 10; // error, ...
28
votes
10answers
5k views

Adding scripting functionality to .NET applications

I have a little game written in C#. It uses a database as back-end. It's a trading card game, and I wanted to implement the function of the cards as a script. What I mean is that I essentially have ...
52
votes
1answer
3k views

TargetedPatchingOptOut: “Performance critical to inline across NGen image boundaries”?

Been going through some framework classes using reflector and noticed a number of the methods and properties have the following attribute [TargetedPatchingOptOut("Performance critical to inline ...
15
votes
4answers
2k views

C# compiler number literals

Does anyone know the full list of C# compiler number literal modifiers? By default declaring '0' makes it an Int32 and '0.0' makes it a 'Double'. I can use the literal modifier 'f' at the end to ...
97
votes
12answers
6k views

How to drive C#, C++ or Java compiler to compute 1+2+3+…+1000?

In a recent interview, I was asked a really strange question. The interviewer asked me how can I compute 1+2+3+...+1000 just using compiler features. This means that I am not allowed to write a ...
94
votes
8answers
38k views

Will #if RELEASE work like #if DEBUG does in C#?

In all the examples I've seen of the #if compiler directive, they use "DEBUG". Can I use "RELEASE" in the same way to exclude code that I don't want to run when compiled in debug mode? The code I ...
11
votes
6answers
7k views

CLR vs JIT

What is the difference between the JIT compiler and CLR? If you compile your code to il and CLR runs that code then what is the JIT doing? How has JIT compilation changed with the addition of generics ...

1 2 3 4 5 10
15 30 50 per page