Saturday, April 26, 2025

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

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