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 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 OriginalGriff 554
1 Gihan Liyanage 338
2 RyanDev 268
3 Sergey Alexandrovich Kryukov 263
4 ChauhanAjay 220
0 Sergey Alexandrovich Kryukov 8,936
1 OriginalGriff 7,891
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2014
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