String Indexof() - C# Tutorial
C# Course / Strings / String Indexof()

String Indexof()

BLUF: Mastering String Indexof() is essential for building robust applications with the .NET ecosystem. This tutorial provides clear explanations and practical examples to help you understand and apply this C# concept.
Enterprise Development Tip: String Indexof()

C# is a powerful, modern language for enterprise solutions. Discover how String Indexof() enhances your development workflow in the guide below.

The C# IndexOf method is employed to retrieve the position of a particular character within a string, providing the index as an integer value.

Signature

Example

public int IndexOf(Char ch)
public int IndexOf(Char, Int32)
public int IndexOf(Char, Int32, Int32)
public int IndexOf(String)
public int IndexOf(String, Int32)
public int IndexOf(String, Int32, Int32)
public int IndexOf(String, Int32, Int32, StringComparision)
public int IndexOf(String, Int32, StringComparision)
public int IndexOf(String, StringComparision)

Parameters

ch: it is a character type parameter.

Return

It returns an integer value.

C# String IndexOf Method Example

Example

using System;  
    public class StringExample  
    {  
        public static void Main(string[] args)  
        {  
          string s1 = "Hello C#";
          int index = s1.IndexOf('e');
          Console.WriteLine(index);
        }  
    }

Output:

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience