GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Python Technologies
  • Databases
  • Computer Programming
  • Web Development
  • Java Technologies
  • Computer Science
  • Mobile Development
  • Big Data & Analytics
  • Microsoft Technologies
  • DevOps
  • Latest Technologies
  • Machine Learning
  • Digital Marketing
  • Software Quality

This view

  • Original page
  • New address

GeezerVison is showing www.tutorialspoint.com — C# String - EndsWith() Method

Csharp Tutorial
  • C# - Home
  • C# - Overview
  • C# - Environment
  • C# - Program Structure
  • C# - Basic Syntax
  • C# - Data Types
  • C# - Type Conversion
  • C# - Variables
  • C# - Constants
  • C# - Operators
  • C# - Arithmetic Operators
  • C# - Assignment Operators
  • C# - Relational Operators
  • C# - Logical Operators
  • C# - Bitwise Operators
  • C# - Miscellaneous Operators
  • C# - Operators Precedence
  • C# Conditional Statements
  • C# - Decision Making
  • C# - If
  • C# - If Else
  • C# - Nested If
  • C# - Switch
  • C# - Nested Switch
  • C# - Switch Expressions
  • C# Control Statements
  • C# - Loops
  • C# - For Loop
  • C# - While Loop
  • C# - Do While Loop
  • C# - Nested Loops
  • C# - Break
  • C# - Continue
  • C# - Foreach Loop
  • C# - Goto Statement
  • C# OOP & Data Handling
  • C# - Encapsulation
  • C# - Methods
  • C# - Nullables
  • C# - Arrays
  • C# - Strings
  • C# - Structure
  • C# - Enums
  • C# - Classes
  • C# - Inheritance
  • C# - Polymorphism
  • C# - Operator Overloading
  • C# - Interfaces
  • C# - Namespaces
  • C# - Preprocessor Directives
  • C# - Regular Expressions
  • C# - Custom Exceptions
  • C# - Exception Handling
  • C# - File I/O
  • C# Advanced Tutorial
  • C# - Attributes
  • C# - Reflection
  • C# - Properties
  • C# - Indexers
  • C# - Delegates
  • C# - Events
  • C# - Collections
  • C# - Generics
  • C# - LINQ
  • C# - IEnumerable vs IEnumerator
  • C# - Anonymous Methods
  • C# - Unsafe Codes
  • C# - Tasks and Parallel Programming
  • C# - Multithreading
  • C# - Extension Methods
  • C# - Lambda Expressions
  • C# - Async and Await
  • C# Modern Features
  • C# - Tuples
  • C# - Records
  • C# - Pattern Matching Enhancements
  • C# - Top-level Statements
  • C# - Nullable Reference Types
  • C# - What's New in C# 11 / 12 / 13
  • C# - Global Usings
  • C# - File-Scoped Namespaces
  • C# Practical & Advanced Usage
  • C# - JSON & XML Handling
  • C# - Data Serialization & Deserialization
  • C# - REST API Calls with Httpclient
  • C# - Dependency Injection
  • C# - Unit Testing with NUnit, xUnit & MSTest
  • C# - Package Management with NuGet
  • C# Useful Resources
  • C# - Developer's AI Tools
  • C# - Questions and Answers
  • C# - Cheatsheet
  • C# - Quick Guide
  • C# - Useful Resources
  • C# - Discussion
  • C# - Online Compiler
Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Online Resume Builder
  • HR Interview Questions
  • Computer Glossary
  • Who is Who

C# String - EndsWith() Method



Previous
Quiz
Next

The C# String EndsWith() method is used to check whether this string ends with the specified string/character or not.

If the value is null this method throw an ArgumentNullException.

Syntax

Following is the syntax of the C# string EndsWith() method −

public bool EndsWith (char/string value);

Parameters

This method accepts only one parameter, either character or string. It compares the character to the character at the end of this object or the string to the substring at the end of this object.

Return value

This method returnstrue if the value matches the end of this object or instance; otherwise,it returns false.

Example 1: Check for The Characters

Following is the basic example of theEndsWith()method to check whether the specified character is available at the end of the string −

    
using System;
class Program {
   static void Main() {
      string str = "Hello, tutorialspoint";
      bool res = str.EndsWith('t');
      Console.WriteLine(res);
   }
}

Output

Following is the output −

True

Example 2: Check for The String

Let us look another example of the EndsWith() method. Here, we check for a string whether it is available at the end of the string or not −

using System;
class Program {
   static void Main() {
      string str = "Hello, tutorialspoint";
      bool res = str.EndsWith("point");
      Console.WriteLine("The string is available at the end: " + res);
   }
}

Output

Following is the output −

The string is available at the end: True

Example 3: If Character is Not Present at The End

In this example, we use the EndsWith() method to check a character is present at the end of the string. If not, then this method returns false −

using System;
class Program {
   static void Main() {
      string str = "Hello, tutorialspoint";
      bool res = str.EndsWith('P');
      Console.WriteLine("The character is available at the end: " + res);
   }
}

Output

Following is the output −

The character is available at the end: False

Example 4: If a String Ends with a Specific Substring

The below example uses the conditional statement to display the statement if the string ends with a specific substring −

using System;
class Program {
   static void Main() {
      string str = "Hello, tutorialspoint";
      bool res = str.EndsWith("spoint");
      Console.Write(res == true 
         ? "The specified string is available in this string" 
         : "The specified string is not available in the string");
   }
}

Output

Following is the output −

The specified string is available in this string
csharp_strings.htm
Tutorix - AI Tutor
Previous Quiz Next
Advertisements
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.