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?
1 Answer
You can use CSharpCodeProvider to compile the input text. If it built successfully, it's c# code.
2 Comments
VerbxteneSkillz
I only want to know if its code, not if its right code
Hyarus
@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