Which code segment should you use?

You are developing a method that searches a string for a substring.
The method will be localized to Italy.
Your method accepts the following parameters: The string to be searched, which is named searchList
The string for which to search, which is named searchValue You need to write the code.
Which code segment should you use?

You are developing a method that searches a string for a substring.
The method will be localized to Italy.
Your method accepts the following parameters: The string to be searched, which is named searchList
The string for which to search, which is named searchValue You need to write the code.
Which code segment should you use?

A.
return searchList.IndexOf(searchValue);

B.
CompareInfo comparer = new CultureInfo(“it-IT”).CompareInfo;
return comparer.Compare(searchList, searchlist, searchValue);

C.
Culture comparer = new CultureInfo(“it-IT”);
if (searchList.IndexOf(searchValue) > 0) {
return true;
}
else {
return false;
}

D.
CompareInfo comparer = new CultureInfo(“it-IT”).CompareInfo;
if (comparer.IndexOf(searchList, searchValue) > 0) {
return true;
}
else {
return false;
}

Explanation:
CompareInfo implemented a number of methods for culture-sensitive string comparisons.
* A no consideration of Italy
* B CompareInfo is correct, but the Compare method compares two strings and is not in the version shown here is possible
* C is not how it works (also, no longer used comparer)
� D, the IndexOf method of CompareInfo is exactly the sought! CORRECT



Leave a Reply 1

Your email address will not be published. Required fields are marked *


seenagape

seenagape

Correct answer is D