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
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