Click here to Skip to main content
16,021,125 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I get the error

"Type 'ConsoleApplication1.TestClass' already defines a member called 'Test Class' with the same parameter type"

out of this Chaining constructor

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class TestClass
    {
        private string MyName;
        private string Conn;
        private int MyNumber;


        public TestClass() { }

        public TestClass(string myName) : this(myName, "", 0) { }

        public TestClass(string connectionString) : this("", connectionString, 0) { }

        public TestClass(int myNumber) : this("", "", myNumber) { }

        public TestClass(string myName, string connectionString, int myNumber)
        {
           MyName = myName;
           Conn = connectionString;
           MyNumber = myNumber;
        }


    }
}


The messagge is clear but how to make this properly. Any help would be very much appreciated.
Almir
Posted

You have two constructors that have a single string as a argument. You can't do that.

Every constructor that has the same number of parameters as another must have differing argument types.
 
Share this answer
 
You can not use Two Methods with " Same Signature " like this:
" Signature is the name and parameter list of Method "

C#
public void Add(int i) { }
public void Add(int j) { }
 
Share this answer
 
Cause these two function have the save name and same number and type of parameter(Function overloading not work only the signature, the type and number of parameter should be differ)
public TestClass(string myName)

public TestClass(string connectionString)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900