 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# program to find the index of a word in a string
Declare and initialize an array −
string[] str = new string[] {    "Cat",    "Mat",    "Rat" }; Now, ue IndexOf() method to find the index of the word “Mat” −
Array.IndexOf(str, "Mat");
The following is the code −
Example
using System; public class Demo {    public static void Main() {       string[] str = new string[] {          "Cat",          "Mat",          "Rat"       };       Console.WriteLine("Our Array =");       for (int i = 0; i < str.Length; i++) {          string res = str[i];          Console.WriteLine(res);       }       int findIndex = Array.IndexOf(str, "Mat");       Console.Write("Element Mat found at the following index: ");       Console.WriteLine(findIndex);    } }  Output
Our Array = Cat Mat Rat Element Mat found at the following index: 1
Advertisements
 