0

Is there a way of compiling C# code in C? I can do it in C#, but I'm not sure about how to do it, if you even can do it in C. Thanks :)

Note: Preferably C# (.NET)

5
  • I'm not sure if this is what you are thinking, but you can write a C# Language compiler in C. It would take a while for the later versions, but C# 1.1 wouldn't take forever. If you are looking to implement System etc... then yes, that may take near forever. Commented Nov 10, 2013 at 15:44
  • 4
    What are you trying to achieve? Do you want to just call C# code from C? Commented Nov 10, 2013 at 15:46
  • Related posts stackoverflow.com/questions/tagged/clr-hosting Commented Nov 10, 2013 at 15:49
  • 1
    And related article codeproject.com/Articles/416471/CLR-Hosting-Customizing-the-CLR Commented Nov 10, 2013 at 15:51
  • What's the question? You can't compile anything 'in C', but you can compile anything if you have a compiler for it on your platform. Commented Nov 13, 2013 at 2:00

3 Answers 3

2

You can load CLR into your process (it's a COM component), create the needed objects/interfaces from Sytem.CodeDOM namespace and use them. But that's tedious, and I wouldn't recommend it.

Just call csc.exe from your program.

Sign up to request clarification or add additional context in comments.

Comments

2

No I dont think thats possible unless you are trying to prepare some compilers.

Comments

1

C# code will be executed under CLR( Common Language Runtime Engine) hence it is called ManagedCode. CLR creates proper execution environment for C# code to run properly. C Code is called UnManaged Code as it does not run under CLR. hence C# code can not be compiled in C.

2 Comments

msdn.microsoft.com/en-us/library/ms404385(v=vs.110).aspx — "The hosting API enables unmanaged hosts to integrate the common language runtime (CLR) into their applications".
Of course. That's how all .NET-produced EXE files work, actually: they start as simple Windows process, then load CLR, initialize it, and tell it to go.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.