-1

I have a partial class with a no parameter constructor in a first file. For this partial class, I would like to have another constructor with a parameter in second file.

Unfortunately I get this error :

Class doesn't contain parameterless constructor

I can't add it in the second file, because it already exists in first file.

What's wrong ? Thanks.

First file :

namespace NS
{
    public partial class A
    {
        public A() {...}
    }
}

Second file :

namespace NS
{
    public partial class A
    {
        public A(int MyParam) {...}
    }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
bruno leclerc
  • 333
  • 2
  • 9

1 Answers1

0
namespace NS
{
    class Program
    {
        static void Main()
        {
            var _a1 = new A();
            var _a2 = new A(123);

            System.Console.ReadKey();
        }
    }

    public partial class A
    {
        public A()
        {
            System.Console.WriteLine("Hi from A (parameterless)");
        }
    }

    public partial class A
    {
        public A(int MyParam)
        {
            System.Console.WriteLine("Hi from A (int)");
        }
    }
}

I hope this is what you are after. Sorry if I misunderstood. I am new to this.

Duncan Carr
  • 250
  • 1
  • 5