In my C# Winforms application I have a textbox where the user can enter text. Is there any method/any criteria to check if the entered code is a C# code?
Asked
Active
Viewed 703 times
-1
-
This post may help you: https://stackoverflow.com/questions/475033/detecting-programming-language-from-a-snippet – Mikitori Jul 30 '18 at 11:16
1 Answers
3
You can use CSharpCodeProvider to compile the input text. If it built successfully, it's c# code.

siusiulala
- 1,040
- 1
- 12
- 24
-
-
@VerbxteneSkillz How do you want to distinguish between invalid code and random text? Any common word could be a class, field or property. I think compiling or checking the whole syntax yourself (and I do not recommend to do that) are the only options – Hyarus Jul 30 '18 at 10:51