Click here to Skip to main content
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
AlmirM661
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 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  
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  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 756
1 OriginalGriff 452
2 Tadit Dash 350
3 sanket saxena 329
4 Peter Leow 228
0 Sergey Alexandrovich Kryukov 11,890
1 OriginalGriff 7,335
2 Peter Leow 5,003
3 Abhinav S 3,943
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web03 | 2.8.140421.2 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid