Saturday, April 26, 2025

C# OO - Objects from DLL Files

ExternalClass.cs

using System;
using System.Collections.Generic;
using System.Text;
using LearnCS;

namespace LearnCS
{
    public class ExternalClass
    {
        public int x = 5;
        public string someString = "Some String";
        public char someChar = 'Z';
    }
}

namespace PrintingMethods
{
    public class Printer
    {
        public static void PrintA()
        {
            ExternalClass genericObject = new ExternalClass();
            Console.WriteLine("----------------------------");
            Console.WriteLine(genericObject.x);
            Console.WriteLine(genericObject.someString);
            Console.WriteLine(genericObject.someChar);
        }
    }
}

namespace MultiMethods { 
    public class Multiplicators
    {
        public static void MultiBy2()
        {
            ExternalClass genericObject = new ExternalClass();
            Console.WriteLine("----------------------------");
            Console.WriteLine("Result from MultiBy2 using Generic Object: ");
            Console.WriteLine(genericObject.x * 2);
        }
    }
}

Program.cs

using System;
usimg PrintingMethods;
using MultiMethods;

namespace LearnCS
{
    class Program
    {
        static void Main(string[] args)
        {
            ExternalClass firstObject = new ExternalClass();
            Console.WriteLine(firstObject.x);
            Console.WriteLine(firstObject.someString);
            Console.WriteLine(firstObject.someChar);

            Printer.PrintA();
            Multiplicator.MultiBy2();
            Console.ReadLine();
        }
    }
}

C# OO - Objects from External Namespaces

 ExternalClass.cs

using System;
using System.Collections.Generic;
using System.Text;
using LearnCS;

namespace LearnCS
{
    public class ExternalClass
    {
        public int x = 5;
        public string someString = "Some String";
        public char someChar = 'Z';
    }
}

namespace PrintingMethods
{
    public class Printer
    {
        public static void PrintA() {
            ExternalClass genericObject = new ExternalClass();
            Console.WriteLine("----------------------------");
            Console.WriteLine(genericObject.x);
            Console.WriteLine(genericObject.someString);
            Console.WriteLine(genericObject.someChar);
        }
    }
}

Program.cs

using System;
using PrintingMethods;

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

            ExternalClass firstobject = new ExternalClass();
            Console.WriteLine(firstobject.x);
            Console.WriteLine(firstobject.someString);
            Console.WriteLine(firstobject.someChar);

            Printer.PrintA();            

            Console.ReadLine();
        }
    }
}

C# OO - Objects and External Classes

ExternalClass.cs

using System;
using System.Collections.Generic;
using System.Text;

namespace LearnCS
{
    public class ExternalClass
    {
        public int x = 5;
        public string someString = "Some String";
        public char someChar = 'Z';
    }
}

Program.cs

using System;

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

            ExternalClass firstobject = new ExternalClass();
            Console.WriteLine(firstobject.x);
            Console.WriteLine(firstobject.someString);
            Console.WriteLine(firstobject.someChar);

            Console.WriteLine("----------------------------------");
            ExternalClass secondobject = new ExternalClass();
            Console.WriteLine(secondobject.x);
            Console.WriteLine(secondobject.someString);
            Console.WriteLine(secondobject.someChar);

            Console.ReadLine();
        }
    }
}

C# OO - Objects and Classes

using System;

namespace LearnCS
{
    class Program
    {
        string x = "Generic Characteristic";

        static void Outsider()
        {
            Program generic = new Program();
            Console.WriteLine(generic.x);
        }

        static void Main(string[] args)
        {

            Program firstObject = new Program();
            Console.WriteLine(firstObject.x);

            Program secondObject = new Program();
            Console.WriteLine(secondObject.x);

            Outsider();

            Console.ReadLine();
        }
    }
}

C# OO - DLL Files - How to Create .dll

DirectPrinter.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DirectPrinter
{
    public class DirectA
    {
        public static void DirectPrintA()
        {
            Console.WriteLine("Line from DirectPrintA Method, from DirectA Class");
        }
    }
    public class DirectB
    {
        public static void DirectPrintB()
        {
            Console.WriteLine("Line from DirectPrintB Method, from DirectB Class");
        }
    }
}

Program.cs

using System;
using DirectPrinter;
//using DDPA = DirectPrinter;

namespace LearnCS
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("I am from Main File");

            ExternalSource.ExternalMethod();
            Console.WriteLine("Variable from External Source: " + ExternalSource.x);

            //Stuff from External Source

            DirectA.DirectPrintA();
            DirectB.DirectPrintB();

            Console.ReadLine();
        }
    }
    class ExternalSource
    {
        public static void ExternalMethod()
        {
            Console.WriteLine("But, I am from External Method");
        }

        public static int x = 100;
    }
}

C# OO - Namespaces - External Files

ExternalSource.cs

using System;
using System.Collections.Generic;
using System.Text;

namespace LearnCS
{
    class ExternalSource
    {
        public static void ExternalMethod() {
            Console.WriteLine("But, I am from External Method");
        }

        public static int x = 100;
    }
}

namespace DirectPrinter
{
    class DirectA
    {
        public static void DirectPrintA() {
            Console.WriteLine("Line from DirectPrintA Method, from DirectA Class");
        }
    }
    class DirectB
    {
        public static void DirectPrintB()
        {
            Console.WriteLine("Line from DirectPrintB Method, from DirectB Class");
        }
    }
}

Program.cs

using System;
using DirectPrinter;
//using DDPA = DirectPrinter;

namespace LearnCS
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("I am from Main File");

            ExternalSource.ExternalMethod();
            Console.WriteLine("Variable from External Source: " + ExternalSource.x);

            //Stuff from External Source

            DirectA.DirectPrintA();
            DirectB.DirectPrintB();

            Console.ReadLine();
        }
    }
}

C# OO - Namespaces - Internal

using System;
using InternalA;
//using static InternalA.BackupA;
//using INTA = InternalA.BackupA;

namespace LearnCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int number = 50;
            Console.WriteLine(number);
            Console.WriteLine(Storage.testString);

            Storage.DirectPrint();

            Console.WriteLine("X from InternalA nms: " + BackupA.x);
            Console.WriteLine("Y from InternalA nms: " + BackupA.y);

            Console.ReadLine();        
        }
    }
}

namespace LearnCS 
{ 
    class Storage
    {
        public static string testString = "Some String";
        public static char indivindualChar = 'A';

        public static void DirectPrint() {
            Console.WriteLine("I am from Storage Class");
        }
    }
}

namespace InternalA
{
    class BackupA
    {
        public static int x = 5;
        public static int y = 15;
    }
}

C# - Exceptions - Try..Catch..Finally

using System;

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

            try
            {
                char[] characters = { 'A', 'B', 'C' };
                Console.WriteLine(characters[200]);
            }
            catch (Exception e) {
                Console.WriteLine("Alarm General !!!");
                Console.WriteLine("------------------------------------------");
                Console.WriteLine("Details: " + e.Message);
            }            

        }
    }
}
using System;

namespace LearnCS
{
    class Program
    {      
        static void Main(string[] args)
        {
            try
            {
                char[] characters = { 'A', 'B', 'C' };
                Console.WriteLine(characters[0]);
            }
            catch (Exception e)
            {
                Console.WriteLine("Alarm General !!!");
                Console.WriteLine(e.Message);
            }
            finally {
                Console.WriteLine();
                Console.WriteLine("####################################");
                Console.WriteLine("I Will Be Printed No Matter What !!!");
                Console.WriteLine("####################################");
            }
        }
    }
}

 

NEXT >

INDEX

C# - Method Overloading

using System;

namespace LearnCS
{
    class Program
    {


        static int MultiGrab(int x, int y) {
            return (x + y);
        }

        static string MultiGrab(string x, string y) {
            return (x + " " + y);
        }

        static string MultiGrab(char x, char y) {
            return (x + "" + y);
        }

        static void Main(string[] args)
        {

            Console.WriteLine(MultiGrab(5, 10));
            Console.WriteLine(MultiGrab("Some", "String"));
            Console.WriteLine(MultiGrab('A', 'Z'));

        }
    }
}

 

C# - Change Order of Parameters

using System;

namespace LearnCS
{
    class Program
    {

        static void NamedArguments(int x1, string x2, char x3) {
            Console.WriteLine("Integer: " + x1);
            Console.WriteLine("String: " + x2);
            Console.WriteLine("Char: " + x3);
        }

        static void NormalMethod(int x, int y, int z) {
            Console.WriteLine("1st: " + x);
            Console.WriteLine("2nd: " + y);
            Console.WriteLine("3rd: " + z);
        }

        static void Main(string[] args)
        {

            //NamedArguments(x3: 'Z', x1: 50, x2: "Some String");

            NormalMethod(5, 7, 9);

        }
    }
}

 

C# - Return Value from Method

using System;

namespace LearnCS
{
    class Program
    {

        static int GetStuff() {
            int x = 10;
            int y = 20;
            int z = (x + y);

            return z;
        }

        static int MultipBy2() {
            int multiplied = (GetStuff() * 2);

            return multiplied;

        }

        static void Main(string[] args)
        {

            //Console.WriteLine(GetStuff());

            Console.WriteLine("Result from MultipBy2 Method: " + MultipBy2());
        }        
    }
}

 

C# - Method Parameters and Default Params

using System;

namespace LearnCS
{
    class Program
    {

        static void Calc(double x, double y) {
            Console.WriteLine("Add: " + (x + y));
            Console.WriteLine("Sub: " + (x - y));
            Console.WriteLine("Mul: " + (x * y));
            Console.WriteLine("Div: " + (x / y));
        }

        static void Person(string x, string y) {
            string result = x + " " + y;
            Console.WriteLine(result);

        }

        static void DefDef(int x = 10) {
            Console.WriteLine(x * 2);
        }

        static void Main(string[] args)
        {

            //Calc(10.50, 5.25);
            //Calc(10, 5);

            //Person("John", "Snow");

            DefDef(50);
            DefDef();
            DefDef(100);

        }        
    }
}

 

C# - Methods

using System;

namespace LearnCS
{
    class Program
    {
        static void JustPrinting() {
            Console.WriteLine("I am operation from method JustPrinting");
        }

        static void Multiplicator() {
            JustPrinting();
            JustPrinting();
            JustPrinting();
        }

        static void Main(string[] args)
        {
            Multiplicator();
            Addition();

        }

        static void Addition() {
            int x = 10;
            int y = 20;
            int z = x + y;

            Console.WriteLine("Result: " + z);
        }

    }
}

 

C# - Break & Continue

using System;

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

            for (int i = 0; i < 20; i++) {
                if (i == 10) {
                    break;
                }
                Console.WriteLine(i);
            }
            
        }
    }        
}
using System;

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

            for (int i = 0; i < 20; i++)
            {
                if (i == 15) {
                    continue;
                }
                Console.WriteLine(i);
            }

        }
    }
}
using System;

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

            int i = 0;

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

                if (i == 10) {
                    break;
                }
            }

        }
    }
}
using System;

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

            int i = 0;

            while (i < 20) {
                if (i == 10) {
                    i++;
                    continue;
                }
                Console.WriteLine(i);
                i++;
            }
        }
    }
}

 

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();

        }
    }        
}

 

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