Understanding static classes and methods
All DotNet variables used in the previous recipe had to be instantiated before they could be used, which means that methods called on such variables are executed on a particular instance of that class. Static methods belong to the class itself and can be called without instantiating the variable.
The whole class can be declared as static. In this case, the class does not implement any constructor and all its methods have to be also static. An example of a static class is File
--a .NET class encapsulating file operations.
A non-static class can implement both instance and static methods. RegEx
is an example of a class that has both static and instance methods. RegEx
is a .NET implementation of regular expressions.
How to do it...
In the following recipe, we will see how to use static classes to search for patterns in text lines with regular expressions and save the results in a file.
- Create a worksheet page in the C/SIDE page designer, select the Item...