Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Indicate whether each string in an array ends with a period (".")

C# Sharp String: Exercise-41 with Solution

Write a C# Sharp program to indicate whether each string in an array ends with a period (".").

C# Sharp Exercises: Indicate whether each string in an array ends with a period (".").

Sample Solution:-

C# Sharp Code:

using System;

public class Example41
{
   public static void Main()
   {
      String[] strings = { "Actions speak louder than words", "Hello!", "Python.", 
                           "PHP.", "random" };
      foreach (var value in strings) {
         bool endsInPeriod = value.EndsWith(".");
         Console.WriteLine();
         Console.WriteLine("'{0}' ends in a period: {1}", 
                           value, endsInPeriod);
      }                            
   }
}

Sample Output:

'Actions speak louder than words' ends in a period: False                                                     
                                                                                                              
'Hello!' ends in a period: False                                                                              
                                                                                                              
'Python.' ends in a period: True                                                                              
                                                                                                              
'PHP.' ends in a period: True                                                                                 
                                                                                                              
'random' ends in a period: False

Flowchart :

Flowchart: C# Sharp Exercises - Indicate whether each string in an array ends with a period (".").

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# Sharp program to demonstrates the CopyTo method.
Next: Write C# Sharp program to check whether a string occurs at the end of another string.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.