I am very new to the language. This code is giving me error:
Cannot create an instance of the static class 'System.Tuple'
Operator '!=' cannot be applied to operands of type 'bool' and 'int'
I don't know what I am doing wrong. Can some tell me what is wrong
using(StreamReader rdr = new StreamReader("fileName"))
{
StringBuilder sb = new StringBuilder();
Int32 nc = 0;
Char c;
Int32 lineNumber = 0;
while( (nc == rdr.Read() !=-1 ))
{
c = (Char)nc;
if( Char.IsWhiteSpace(c) )
{
if( sb.Length > 0 )
{
yield return new Tuple( sb.ToString(), lineNumber );
sb.Length = 0;
}
if( c == '\n' ) lineNumber++;
}
else
{
sb.Append( c );
}
}
if( sb.Length > 0 ) yield return new Tuple( sb.ToString(), lineNumber );
}
Tuple classes require type arguments which you must provide:
yield return new Tuple<string, int>( sb.ToString(), lineNumber );
alternatively you can use Tuple.Create
which usually allows the type arguments to be inferred automatically:
yield return Tuple.Create(sb.ToString(), lineNumber);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With