Reputation: 15631
I searched and searched, but couldn't find anything remotely similar. According to everything I've come to know, it should work.
string strTest, strSubTest, strDesc;
using (GenericParser parser = new GenericParser())
{
parser.SetDataSource(@"D:\work.csv");
parser.ColumnDelimiter = @",".ToCharArray();
parser.FirstRowHasHeader = true;
parser.MaxBufferSize = 4096;
parser.MaxRows = 200;
while (parser.Read())
{
strTest = parser["Test"];
strSubTest = parser["Subtest"];
strDesc = parser["Description"];
Console.WriteLine(strTest);
The code that states @",".ToCharArray(); states the error in the title. I've never seen an implicit conversion like that before 'Char?'. Any idea what I did wrong?
If you need some background, I used the GenericParser found here: http://www.codeproject.com/Articles/11698/A-Portable-and-Efficient-Generic-Parser-for-Flat-F
Upvotes: 0
Views: 645
Reputation: 713
the question mark is a modifier to value types like char, int, and double to make them nullable. So where char x = null;
is a syntax error, char? x = null;
works. char?
actually a shorthand syntax for Nullable<char>
. Nullable<T>
can't be used with reference types, as they are already nullable. Nullable<T>
objects have two properties, bool HasValue
, which should be obvious, and T Value
, which returns the encapsulated value if HasValue is true, or throws an exception if it is false.
So, you can't set Delimeter
to a character array, because it is expecting either a character or null.
Upvotes: 0