eval() in c# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

eval() in c#

hello. how i can do something like [ eval(); in js or php ] i will not make a text editor , but i need it in code only ! like : 𝐢𝐧𝐭 𝐱 = 𝐬𝐞𝐜𝐨𝐧𝐝 ; 𝐬𝐭𝐫𝐢𝐧𝐠 𝐟𝐢𝐫𝐬𝐭 = "𝐡𝐞𝐥𝐥𝐨 𝐢'𝐦 𝐨𝐧𝐞"; 𝐬𝐭𝐫𝐢𝐧𝐠 𝐬𝐞𝐜𝐨𝐧𝐝 = "𝐡𝐞𝐥𝐥𝐨 𝐢'𝐦 𝐭𝐰𝐨"; 𝐬𝐭𝐫𝐢𝐧𝐠 𝐭𝐡𝐢𝐫𝐝 = "𝐡𝐞𝐥𝐥𝐨 𝐢'𝐦 𝐭𝐡𝐫𝐞𝐞"; 𝐬𝐭𝐫𝐢𝐧𝐠 𝐟𝐨𝐮𝐫𝐭𝐡 = "𝐡𝐞𝐥𝐥𝐨 𝐢'𝐦 𝐟𝐨𝐮𝐫"; 𝐟𝐮𝐧𝐜(𝐲); { 𝐞𝐯𝐚𝐥(" 𝐱 = " + 𝐲); } func(x); 𝐜𝐨𝐧𝐬𝐨𝐥𝐞.𝐰𝐫𝐢𝐭𝐞(x); // 𝐨𝐮𝐭𝐩𝐮𝐭 : 𝐡𝐞𝐥𝐥𝐨 𝐢'𝐦 𝐭𝐰𝐨 ---------------------------- i need code like this because i have more than 50 if else and switch blocks and more. thanks =) i try the idea here : https://code.sololearn.com/WbiEHdk01g4l/?ref=app

31st Jul 2018, 12:29 PM
Yousef Eabitan
Yousef Eabitan - avatar
2 Answers
+ 2
It can be achieved using System.Data.Compute() method. However I'm not sure if it can do string operations. You can refer the Execute function in the following code to get an idea on how to use it (last method in file). https://code.sololearn.com/cUjWf1uegwh6/?ref=app
31st Jul 2018, 5:31 PM
Rusty.Metal
+ 3
Rusty.Metal Thank You , Yes I Need Something Like This , But I Will Try If This will work with me ❤❤
1st Aug 2018, 1:12 PM
Yousef Eabitan
Yousef Eabitan - avatar