-1

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

1 Answer 1

3

You can use CSharpCodeProvider to compile the input text. If it built successfully, it's c# code.

Sign up to request clarification or add additional context in comments.

2 Comments

I only want to know if its code, not if its right code
@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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.