C#: Check whether a given string ends with "on"
Ends with 'on'
Write a C# Sharp program to check whether a given string ends with "on".
Visual Presentation:

Sample Solution:-
C# Sharp Code:
using System; // Import the System namespace which contains fundamental types and base classes
namespace exercises // Define a namespace called 'exercises'
{
    class Program // Define a class named 'Program'
    {
        static void Main(string[] args) // The entry point of the program
        {
            // Output the result of the test function with different strings as arguments
            Console.WriteLine(test("Hello"));  // Check if "Hello" ends with "on"
            Console.WriteLine(test("Python")); // Check if "Python" ends with "on"
            Console.WriteLine(test("on"));     // Check if "on" ends with "on"
            Console.WriteLine(test("o"));      // Check if "o" ends with "on"
            Console.ReadLine(); // Wait for user input before closing the console window
        }
        // Function definition of test function that takes a string 's1' and returns a boolean value
        public static bool test(string s1)
        {
            // Check if the string 's1' ends with the substring "on"
            return s1.EndsWith("on");
        }
    }
}
Sample Output:
False True True False
Flowchart:

Go to:
PREV : Two Middle Characters of Even-Length String.
NEXT : First and Last n Characters of String.
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
