Click here to Skip to main content
12,749,754 members (35,502 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
I get the error

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

out of this Chaining constructor

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.
Posted 7-Oct-12 5:44am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You can not use Two Methods with " Same Signature " like this:
" Signature is the name and parameter list of Method "

public void Add(int i) { }
public void Add(int j) { }
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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)

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170215.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100