Saturday, April 26, 2025

C# - Array Operations

using System;
using System.Linq;

namespace LearnCS
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] pLanguages = { "Perl", "Python", "Java", "JS", "C++", "C" };
            int[] numbers = { 1, 34, 25, 23442, 56, 56, 56, 100 };

            Console.WriteLine("Position 0: " + pLanguages[0]);
            Console.WriteLine("Position 5: " + pLanguages[5]);

            pLanguages[0] = "Prolog";
            pLanguages[1] = "Lisp";

            foreach (string i in pLanguages) {
                Console.WriteLine(i);
            }

            //Length of Array
            Console.WriteLine("Length of Array : " + pLanguages.Length);

            //For Loop
            for (int x = 0; x < pLanguages.Length; x++) {
                Console.WriteLine("Index of: " + x + " Value: " + pLanguages[x]);
            }

            Array.Sort(numbers);

            foreach (int i in numbers)
            {
                Console.WriteLine(i);
            }

            //System.Linq Namespace

            Console.WriteLine("Sum: " + numbers.Sum());
            Console.WriteLine("Max: " + numbers.Max());
            Console.WriteLine("Min: " + numbers.Min());

            Console.ReadLine();

        }
    }        
}

 

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...