You are developing a C# application that has a requirement to validate some string input data by
using the Regex class.
The application includes a method named ContainsHyperlink. The ContainsHyperlink() method will
verify the presence of a URI and surrounding markup.
The following code segment defines the ContainsHyperlink() method. (Line numbers are included for
reference only.)
The expression patterns used for each validation function are constant.
You need to ensure that the expression syntax is evaluated only once when the Regex object is
initially instantiated.
Which code segment should you insert at line 04?
A.
Option A
B.
Option B
C.
Option C
D.
Option D
Explanation:
RegexOptions.Compiled – Specifies that the regular expression is compiled to an assembly.This yields
faster execution but increases startup time.This value should not be assigned to the Options
property when calling the CompileToAssembly method.
http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regexoptions.aspx
Additional info
http://stackoverflow.com/questions/513412/how-does-regexoptions-compiled-work
D
CultureInvariant
Specifies that cultural differences in language is ignored. For more information, see the “Comparison Using the Invariant Culture” section in the Regular Expression Options topic.
By default, regular expressions in the .NET Framework are interpreted. When a Regex object is instantiated or a static Regex method is called, the regular expression pattern is parsed into a set of custom opcodes, and an interpreter uses these opcodes to run the regular expression. This involves a tradeoff: The cost of initializing the regular expression engine is minimized at the expense of run-time performance.
You can use compiled instead of interpreted regular expressions by using the RegexOptions.Compiled option. In this case, when a pattern is passed to the regular expression engine, it is parsed into a set of opcodes and then converted to Microsoft intermediate language (MSIL), which can be passed directly to the common language runtime. Compiled regular expressions maximize run-time performance at the expense of initialization time.