Consider the given below arrays
string[ ] countries = {"Denmark", "China", "Austria”, “England", "Belgium"};
int[ ] myNumbers = {6, 1, 8, 9, 2};
Write a C# program to perform the following array methods
•The string array should sort the countries in ascending or alphabetically order
•The integer array should print all numbers in reverse order
•Use only foreach loop for accessing the array’s elements
Make sure to add comments in the code. The program should generate the output as given in below sample output.
programming-in-C-sharp-questions-25-09-2021-0643.JPG


Answer:

using System;
using System.Linq;

namespace Qstn2 // name of project
{
class SortArrays // class name
{
static void Main(string[] args)
{
//initialize arrays as below
string[] countries = { "Denmark", "China", "Austria", "England", "Belgium" };
int[] myNumbers = { 6, 1, 8, 9, 2 };
Console.WriteLine("The sorted list of countries in anscending order as below");
//access array elements
//sort countries array
Array.Sort(countries);
foreach(String m in countries){
Console.WriteLine(m);
}
//reverse numbers array
Array.Reverse(myNumbers);
Console.WriteLine("Numbers in reverse order are given as below");
foreach(int g in myNumbers){
Console.WriteLine(g);
}
Console.ReadKey();
}
}
}

programming-in-C-sharp-questions-25-09-2021-0647.JPG


Share To Friends Via:
        






More Questions For Programming in C Sharp:



  The given below single dimension array of type integers called MyNumbers. int[ ] myNumbers = {3, 3, 1, 5, 2, 4, 1} Write a C# program that should display the output based on the following requirements. •It should display the smallest value in an array •It should display the largest value in an array •It should display the sum of all elements in an array Make sure to add comments in the code. (Answered)
The given below single dimension array of type integers called MyNumbers. int[ ] myNumbers = {3, 3, 1, 5, 2, 4, 1} Write a C# program that should display the output based on the following requirements. •It should display the smallest value in an array •It should display the largest value in an array •It should display the sum of all elements in an array Make sure to add comments in the code. .
Posted On:Sat 25, September 2021 06:38:57 am
  Write a C# program that should declare & initializes single dimension array of type string called colors. The program should display the output based on the following requirements. •It should display an array size using length property. •It should access each element in an array using for loop only. Make sure to add comments in the code. The program should generate the output as given in below (Answered)
Write a C# program that should declare & initializes single dimension array of type string called colors. The program should display the output based on the following requirements. •It should display an array size using length property. •It should access each element in an array using for loop only. Make sure to add comments in the code. The program should generate the output as given in below .
Posted On:Sat 25, September 2021 06:52:06 am
  Answer the following concepts of declaring and initializing an array in C# programming language using different ways. A.Declare an array of five elements of type integer with keyword new, the array name is called values. Do not add elements to an array. B.Declare an array of four elements of type string with keyword new, the array name is called seasons. Add elements to an array. C.Declare an (Answered)
Answer the following concepts of declaring and initializing an array in C# programming language using different ways. A.Declare an array of five elements of type integer with keyword new, the array name is called values. Do not add elements to an array. B.Declare an array of four elements of type string with keyword new, the array name is called seasons. Add elements to an array. C.Declare an .
Posted On:Sat 25, September 2021 06:56:12 am
  What are Methods in C-sharp programming language, what is the use of it and how to use methods using parameters? Write a summary of at least 300 words with at least two different examples of C-sharp programs. Make sure to use your own wording. No copy paste from the internet or textbook is allowed. Include at least one reference. (Answered)
What are Methods in C-sharp programming language, what is the use of it and how to use methods using parameters? Write a summary of at least 300 words with at least two different examples of C-sharp programs. Make sure to use your own wording. No copy paste from the internet or textbook is allowed. Include at least one reference. .
Posted On:Sat 25, September 2021 07:02:52 am

More Questions Categories:


About Us

Contact us

Terms of use | Privacy policy

Follow Us:               

All Rights Reserved © 2024; pscustudies.com