If you're doing this for a real-world scenario, there are good commercial options available. You need to look at using the CodeDom classes which can take your input text and convert it into an object model which can then be compiled into an assembly.
If there are compiler errors, they will be returned as a collection of CompilerError
objects. These will tell you the line number, character number, and error message, so you can display the error.
There are significant drawbacks to using CodeDom
, however. It is older technology and has not been updated to keep pace with the language changes so there are limitations in what it can parse. If you want to write your own parser, you need to look at language tools like lexx and yacc or Roslyn.