-1

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

        }
    }
Yul P
  • 3
  • 3
  • 2
    "Works as implemented." The code does exactly what you told it to do, but you're reading it as what you expect it to do, not what you told it to do. This is the absolute best time to start learning [how to use the debugger](https://learn.microsoft.com/en-us/visualstudio/debugger/debugger-feature-tour). If you have to resort to asking questions for this kind of help, you're going to have a rough time learning how to program in *any* language. – madreflection Dec 07 '22 at 17:07

1 Answers1

2

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?

Colin Desmond
  • 4,824
  • 4
  • 46
  • 67
  • Once i stepped through in the debugger I found null reference exception. Anyways! It works with Enter , thanks for help! – Yul P Dec 07 '22 at 17:07