Click here to Skip to main content
11,578,524 members (59,933 online)
Rate this: bad
good
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.
Almir
Posted 7-Oct-12 4:44am
AlmirM666
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
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) { }
  Permalink  
Rate this: bad
good
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)
  Permalink  

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

  Print Answers RSS
0 Peter Leow 135
1 OriginalGriff 113
2 Richard MacCutchan 85
3 Afzaal Ahmad Zeeshan 75
4 Frankie-C 75
0 OriginalGriff 933
1 Sergey Alexandrovich Kryukov 740
2 Abhinav S 573
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 403


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2015
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