0

I was wondering if this would be possible.

string someString = "int somFunction(int a, int b){
    a = a+b;
    return a;    
}"

is it possible to make to make the function in string work? If yes, how? Thank you. By the way the point of doing this is because I want to write function in Excel and want to read the excel and make the function work..

Here is a sample of Excel this

thank you

  • It is possible but probably not a good way to go about things. Can you add more the question and give us more details on the excel document? – dev8989 Dec 28 '17 at 01:41
  • A different way to do this would be to require your users to make DLLs or NuGet packages that obey some API (e.g. a publicly visible `Algorithm` static method) and for them to put the paths to those in the Excel file. You can then load these assemblies. If you want to continue using the approach you have right now, you basically have to build the assembly yourself, in memory. – Asad Saeeduddin Dec 28 '17 at 01:49
  • Enter C# code in an Excel file? That's really strange. Why not just have that `a+b` in Excel and make your app parse that? – Andrew Dec 28 '17 at 02:59
  • No I meant the otherside. Reading Excel file by C# code. Also above code (a+b) was just an example. I want to read and use function longer than at least ten lines which is written in string in the excel file. – K. Shinwook Dec 28 '17 at 04:54
  • I'm totally lost. I don't know if you want to parse C#, read an xlsx file with C# or somehow write a function in Excel. Please, re-read your question and re-write it so it's understandable. – Andrew Dec 29 '17 at 02:38
  • sorry for my misunderstanding. Andrew you were right about what i meant to say. What I want to do is followings. 1. Enter C# code in Excel file Like picture I made in my question. 2. I want to read the Excel file and then register and use the function written in Excel file. – K. Shinwook Dec 29 '17 at 05:04

0 Answers0