Saturday, April 26, 2025

C# - Arrays and Foreach Loop

using System;

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 };

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

            foreach (int x in numbers) {
                Console.WriteLine(x * 3);
            }

        }
    }        
}

 

C# - While & Do..While Loop

using System;

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

            int i = 0;

            while (i < 20) {
                Console.WriteLine(i);
                i++;
            }
           
        }
    }        
}
using System;

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

            int i = 0;

            do
            {
                Console.WriteLine(i);
                i++;
            } while (i < 25);
           
        }
    }        
}

 

C# - For Loop

using System;

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

            for (int i = 0; i <= 500; i = i + 10) {
                Console.WriteLine(i);
            }

        }
    }        
}

 

C# - Switch Statement

using System;

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

            int lang = 500;

            switch (lang) {
                case 1:
                    Console.WriteLine("Perl");
                    break;
                case 2:
                    Console.WriteLine("Python");
                    break;
                case 3:
                    Console.WriteLine("C++");
                    break;
                case 4:
                    Console.WriteLine("PHP");
                    break;
                case 5:
                    Console.WriteLine("Java");
                    break;
                default:
                    Console.WriteLine("Unknown");
                    break;
            }

        }
    }        
}

 

C# - if..else if..else

using System;

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

            if (25 > 50) {
                Console.WriteLine("25 is G reater than 50");
            }
            if (25 < 50) {
                Console.WriteLine("25 is Smaller than 50");
            }
            if (25 == 25)
            {
                Console.WriteLine("Numbers are Equal");
            }

        }
    }        
}
using System;

namespace LearnCS
{
    class Program
    {
        static void Main(string[] args)
        {
            if (100 > 50) {
                Console.WriteLine("100 is Greater than 50");
            }
            if (25 < 50) { 
                Console.WriteLine("25 is Smaller than 50");
            }
            if (50 == 50) {
                Console.WriteLine("Number are Equal");
            }

        }
    }        
}
using System;

namespace LearnCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = 50;
            int y = 50;

            if (x > y)
            {
                Console.WriteLine(x + " is Greater than " + y);
            }
            else if (x < y)
            {
                Console.WriteLine(x + " is Smaller than " + y);
            }
            else {
                Console.WriteLine("Numbers are Equal");
            }
        }
    }        
}

C# - Math Operations - Max, Min, Abs, Sqrt, Round

using System;

namespace LearnCS
{
    class Program
    {
        static void Main(string[] args)
        {
            float fNumber = 10.56F;
            float sNumber = 12.20F;
            int tNumber = 9;

            Console.WriteLine("Max: " + Math.Max(fNumber, sNumber));
            Console.WriteLine("Min: " + Math.Min(fNumber, sNumber));
            Console.WriteLine("Sqrt: " + Math.Sqrt(tNumber));
            Console.WriteLine("Abs: " + Math.Abs(-45));
            Console.WriteLine("Round: " + Math.Round(5.55));
            Console.WriteLine("Round: " + Math.Round(5.2));

            Console.ReadLine();
        }
    }        
}

 

C# - String Operations

using System;

namespace LearnCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string someString = "Of all things i've lost i miss my mind the most";

            Console.WriteLine("Length: " + someString.Length);

            Console.WriteLine("To Upper: " + someString.ToUpper());
            Console.WriteLine("To Lower: " + someString.ToLower());

            string oneMore = " Hack The Planet";

            string result = string.Concat(someString, oneMore);
            Console.WriteLine(result);

            string interpolation = $"First One: {someString} and Second One: {oneMore}";
            Console.WriteLine(interpolation);

            Console.WriteLine(someString[0]);
            Console.WriteLine(someString[1]);
            Console.WriteLine(someString[2]);
            Console.WriteLine(someString[3]);
            Console.WriteLine(someString[4]);

            Console.WriteLine(someString.IndexOf("t"));
            Console.ReadLine();
        }
    }        
}

 

C# - User Input & Basic Operations

using System;

namespace LearnCS
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("#---------------------------------------#");

            Console.WriteLine("Enter First Number: ");
            string firstNumber = Console.ReadLine();
            float fNumber = Convert.ToInt32(firstNumber);

            Console.WriteLine("Enter Second Number: ");
            string secondNumber = Console.ReadLine();
            float sNumber = Convert.ToInt32(secondNumber);

            Console.WriteLine("#---------------------------------------#");

            Console.WriteLine("Datatype: " + fNumber.GetType() + " Value: " + fNumber);
            Console.WriteLine("Datatype: " + sNumber.GetType() + " Value: " + sNumber);

            Console.WriteLine("Add: " + (fNumber + sNumber));
            Console.WriteLine("Sub: " + (fNumber - sNumber));
            Console.WriteLine("Mul: " + (fNumber * sNumber));
            Console.WriteLine("Div: " + (fNumber / sNumber));
            Console.WriteLine("Mod: " + (fNumber % sNumber));
        }
    }        
}

 

C# - Data Types & Type Detection

using System;

namespace LearnCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int number = 5;
            float fNumber = 5.521F;
            double dNumber = 10.56454654D;
            long lNumber = 734689172634978653L;

            string someString = "Bunch of Words";
            char zChar = 'Z';

            double sciNumber = 15.36E23D;

            Console.WriteLine("Value: " + number + " Datatype: " + number.GetType());
            Console.WriteLine(fNumber);
            Console.WriteLine(dNumber);
            Console.WriteLine(lNumber);
            Console.WriteLine(someString);
            Console.WriteLine(zChar);
            Console.WriteLine(sciNumber);

            Console.WriteLine("---------------------------------------");

            Console.WriteLine(number.GetType());
            Console.WriteLine(fNumber.GetType());
            Console.WriteLine(dNumber.GetType());
            Console.WriteLine(lNumber.GetType());
            Console.WriteLine(someString.GetType());
            Console.WriteLine(zChar.GetType());
            Console.WriteLine(sciNumber.GetType());
        }
    }        
}

 

C# - Variables, Constants, Concatenation

using System;

namespace LearnCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string name = "Natalie";
            string lastName = "Dormer";

            int someNumber = 50;

            const int voltage = 12;

            Console.WriteLine(name);
            Console.WriteLine(lastName);

            //Console.Write(name);
            //Console.Write(lastName);

            Console.WriteLine("Custom Report: " + name + " " + lastName + " something more");

            lastName = "XXX";
            Console.WriteLine(lastName);

            Console.WriteLine(someNumber);
            Console.WriteLine(voltage);      
        }
    }        
}

 

C# - Line by Line Explanations

using System;

namespace LearnCS
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Some String");           
        }
    }        
}

 

C# - Introduction & Installation

C# (pronounced "C sharp") is a modern, multi-paradigm programming language developed by Microsoft in the early 2000s.

It is designed to be simple, safe, and efficient, and is widely used for developing a variety of applications on the .NET framework, including Windows desktop applications, web applications, mobile apps, games, and more. 

The .NET Framework is a software framework developed by Microsoft that provides a platform for building, deploying, and running applications. It includes a large library of pre-built code and tools that developers can use to create a wide range of applications.

using System;

namespace LearnCS
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Some String");           
        }
    }        
}

Quick explanation, for now:

This C# code defines a class called Program inside a namespace called LearnCS. The Main method is the entry point of the program, which is executed when the program starts.

Inside the Main method, a message "Some String" is printed to the console using the Console.WriteLine method.

In order to use the Console class, the System namespace is being imported using the using keyword at the beginning of the file.

OpenBSD - Manual Partitioning

How To Install MySQL Server on OpenBSD

How To Install Firefox on OpenBSD

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 .  ...