w3resource
C# Sharp Programming Exercises

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?



New Content: Composer: Dependency manager for PHP, R Programming