Saturday, April 26, 2025

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

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