Home > Net >  Partial class problem in c# : not possible to invoke a method correctly
Partial class problem in c# : not possible to invoke a method correctly

Time:12-08

I'm new to c# and just started studying the partial classes topic. Made some practice but I dont understand why when I do run a programm the console stamps only the method from the 1st partial class and completely ignores the second partial class when I'm invoking the "AndAgainDoSomething()" method.

Maybe it's because in can not open second console without closing the first one ?

public interface ISomething
    {

    }

    public partial class MyInterface : ISomething
    {
        public void DoSomething()
        {
            //some stuff
            Console.WriteLine("Thats pt1 of what my partial class is doing ");
            Console.ReadLine();
        }
    }

    public partial class MyInterface
    {
        public int MyProperty { get; set; }
        public int MyProperty1 { get; set; }

        public void AndAgainDoSomething()
        {
            Console.WriteLine("Thats pt2 of what my partial class is doing ");
            Console.ReadLine();
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            var firstPart = new MyInterface();
            firstPart.DoSomething();
            firstPart.AndAgainDoSomething();

        }
    }

CodePudding user response:

After the Console.WriteLine in DoSomething, there is a Console.ReadLine, so you need to press Enter for the code to move on and execute the second method?

Have you added breakpoints and stepped through in the debugger to see where the code is stopping?

  • Related