Call C# code in C
I want to call c# code in c is it possible if so give me simple example to multiply by calling c# multiply function from c
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Vithal WadjeRank #19 · 47.2K reputationPosted Nov 30, 2012, 1:58 AM EST
VulpesRank #55 · 29.2K reputationPosted Nov 30, 2012, 2:25 AM EST
sridevi pc10 reputationPosted Nov 30, 2012, 2:40 AM EST
Thanks for the reply
when i try to do step to am getting errorr message "
multiply.cs(3,21): error CS0106: The modifier 'static' is not valid for this
item "
csc /t:library multiply.cs
should i make Multiply function as non staticsridevi pc10 reputationPosted Nov 30, 2012, 2:41 AM EST
sridevi pc10 reputationPosted Nov 30, 2012, 2:43 AM EST
Vithal WadjeRank #19 · 47.2K reputationPosted Nov 30, 2012, 2:46 AM EST
VulpesRank #55 · 29.2K reputationPosted Nov 30, 2012, 2:48 AM EST
If that's the case, then it's OK to remove 'static' before 'class' but you must leave it in for the Multiply method itself.
sridevi pc10 reputationPosted Nov 30, 2012, 3:32 AM EST
VulpesRank #55 · 29.2K reputationPosted Nov 30, 2012, 3:44 AM EST
No worries, it's not something you'd be likely to know unless (like me) you've spent years inter-operating with unmanaged code.
@ sridevi pc
If the console is closing before you've time to read the output, I'd try inserting the highlighted lines towards the end of the main() function in test.c:
If that's the case then you'll need to do more to the IL than just adding an .export directive (ilasm 2.0 does most of this for you). I've highlighted all the lines that need inserting:
VulpesRank #55 · 29.2K reputationPosted Jan 10, 2013, 12:20 AM EST
The only obvious problem I can see is that 'List' is used without a type parameter if this is the same List as the framework class, System.Collections.Generic.List
I'd have thought it needed to be List