In our .Net 1.1 days we used to check whether a string object contains a specified string(text) using IndexOf method.
Here is the typical code to check the existence of a string in an string object.
//Sample code
string sName = "John Smith";
if(sName.IndexOf("Smith") > -1) {
//Smith exists in string object sName
}
Now let's take a closer look at the above code...... What we want is to know whether an instance of string contains some string(text).
Did I say contains......that's exactly C# .Net 2.0 provides us with.
Let's revisit the same functionality using 2.0
//Sample code
string sName = "John Smith";
if(sName.Contains("Smith")) {
//Smith exists in string object sName
}
Wallah.....it's so simple and sophisticated.