locked
Pattern Matching RRS feed

  • Question

  •  

    Hi All,

            Is pattern matching possible in C#. If it's possible how can i do it.

     

     

    With Regards,

    litu

    Friday, December 14, 2007 6:31 AM

Answers

  • Hi,

     

    If you mean regular expressions, you can use the Regex class built in the .NET Framework Class Library. For example, the Regex.Match method searches an input string for an occurrence of a regular expression.

     

    By default a regular expression works interpretively which means it is not complied. To improve performance you can compile it by passing a RegexOptions.Compiled to the Regex constructor. Then the expression is compiled when being constructed at runtime.

     

    A further step is to pre-compile the expression into an assembly with the Regex.CompileToAssembly  method.

     

    Best Regards

    Chunsheng Tang

     

    Monday, December 17, 2007 9:06 AM