First try collection class- strange error

  • Thread starter Thread starter mp
  • Start date Start date
M

mp

I copied a sample code and modified name to try collection class
here's the definition (constructor has two args)
I get error saying "Error 1 'MoldParts' does not contain a constructor that
takes '2' arguments "
at the bottom of this post is the line that generates the error (called from
a form)

public class MoldParts : IEnumerable
{
private string[] elements;

MoldParts(string source, char[] delimiters)
{
// Parse the string into tokens:
elements = source.Split(delimiters);
}

// IEnumerable Interface Implementation:
// Declaration of the GetEnumerator() method
// required by IEnumerable
public IEnumerator GetEnumerator()
{
return new TokenEnumerator(this);
}


// Inner class implements IEnumerator interface:
private class TokenEnumerator : IEnumerator
{
private int position = -1;
private MoldParts t;

public TokenEnumerator(MoldParts t)
{
this.t = t;
}

// Declare the MoveNext method required by IEnumerator:
public bool MoveNext()
{
if (position < t.elements.Length - 1)
{
position++;
return true;
}
else
{
return false;
}
}

// Declare the Reset method required by IEnumerator:
public void Reset()
{
position = -1;
}

// Declare the Current property required by IEnumerator:
public object Current
{
get
{
return t.elements[position];
}
}
}
}

//here is the line that creates the error
static void TestCollection()
{
// Testing Tokens by breaking the string into tokens:
MoldParts f = new MoldParts("This is a sample sentence.", new
char[] { ' ', '-' });

foreach (string item in f)
{
System.Console.WriteLine(item);
}
}

what am i missing? it appears to me that the constructor does take two
arguments????

thanks

mark
 
mp said:
public class MoldParts : IEnumerable
{
[...]
MoldParts(string source, char[] delimiters)
[...]
what am i missing? it appears to me that the constructor does take two
arguments????

Try adding "public" to the declaration of the constructor so that it
has the same accessibility as the class.
 
mp said:
I copied a sample code and modified name to try collection class
here's the definition (constructor has two args)
I get error saying "Error 1 'MoldParts' does not contain a constructor that
takes '2' arguments "
at the bottom of this post is the line that generates the error (called from
a form)

public class MoldParts : IEnumerable
{
private string[] elements;

MoldParts(string source, char[] delimiters)
{
// Parse the string into tokens:
elements = source.Split(delimiters);
}

Everything is 'Private' unless told otherwise.

Public MoldParts() //constructor
{

}
 
Thanks Mr. Arnold and Alberto,
seems the error msg is a bit misleading (to a newbie).
thanks
mark

Mr. Arnold said:
mp said:
I copied a sample code and modified name to try collection class
here's the definition (constructor has two args)
I get error saying "Error 1 'MoldParts' does not contain a constructor
that takes '2' arguments "
at the bottom of this post is the line that generates the error (called
from a form)

public class MoldParts : IEnumerable
{
private string[] elements;

MoldParts(string source, char[] delimiters)
{
// Parse the string into tokens:
elements = source.Split(delimiters);
}

Everything is 'Private' unless told otherwise.

Public MoldParts() //constructor
{

}
 
The best way is to make use of the snippets: ctor

regards => "Tanzim Saqib"
designer => "British Telecom"

Microsoft "Most Valuable Professional" (MVP) awardee in ASP.NET
https://mvp.support.microsoft.com/profile/Saqib


mp said:
Thanks Mr. Arnold and Alberto,
seems the error msg is a bit misleading (to a newbie).
thanks
mark

Mr. Arnold said:
mp said:
I copied a sample code and modified name to try collection class
here's the definition (constructor has two args)
I get error saying "Error 1 'MoldParts' does not contain a constructor
that takes '2' arguments "
at the bottom of this post is the line that generates the error (called
from a form)

public class MoldParts : IEnumerable
{
private string[] elements;

MoldParts(string source, char[] delimiters)
{
// Parse the string into tokens:
elements = source.Split(delimiters);
}

Everything is 'Private' unless told otherwise.

Public MoldParts() //constructor
{

}
 
I don't see that in my express version...been searching on google to see if
there are samples to download - no success yet but there are hundreds of
hits to dig through so i'm sure it's out there somewhere..
do you know where I'd find this?
thanks
mark

Tanzim Saqib said:
The best way is to make use of the snippets: ctor

regards => "Tanzim Saqib"
designer => "British Telecom"

Microsoft "Most Valuable Professional" (MVP) awardee in ASP.NET
https://mvp.support.microsoft.com/profile/Saqib


mp said:
Thanks Mr. Arnold and Alberto,
seems the error msg is a bit misleading (to a newbie).
thanks
mark

Mr. Arnold said:
mp wrote:
I copied a sample code and modified name to try collection class
here's the definition (constructor has two args)
I get error saying "Error 1 'MoldParts' does not contain a constructor
that takes '2' arguments "
at the bottom of this post is the line that generates the error (called
from a form)

public class MoldParts : IEnumerable
{
private string[] elements;

MoldParts(string source, char[] delimiters)
{
// Parse the string into tokens:
elements = source.Split(delimiters);
}

Everything is 'Private' unless told otherwise.

Public MoldParts() //constructor
{

}
 
nevermind! Found it in C# express...I had been working on a vb.net project
at the time and it wasn't in vb express.
sorry
mark

mp said:
I don't see that in my express version...been searching on google to see if
there are samples to download - no success yet but there are hundreds of
hits to dig through so i'm sure it's out there somewhere..
do you know where I'd find this?
thanks
mark

Tanzim Saqib said:
The best way is to make use of the snippets: ctor

regards => "Tanzim Saqib"
designer => "British Telecom"

Microsoft "Most Valuable Professional" (MVP) awardee in ASP.NET
https://mvp.support.microsoft.com/profile/Saqib


mp said:
Thanks Mr. Arnold and Alberto,
seems the error msg is a bit misleading (to a newbie).
thanks
mark

mp wrote:
I copied a sample code and modified name to try collection class
here's the definition (constructor has two args)
I get error saying "Error 1 'MoldParts' does not contain a constructor
that takes '2' arguments "
at the bottom of this post is the line that generates the error
(called from a form)

public class MoldParts : IEnumerable
{
private string[] elements;

MoldParts(string source, char[] delimiters)
{
// Parse the string into tokens:
elements = source.Split(delimiters);
}

Everything is 'Private' unless told otherwise.

Public MoldParts() //constructor
{

}
 
Back
Top