So, I came across the following:
Console.WriteLine(currentRow["Projekt"]); Console.WriteLine($"{currentRow["Projekt"]}"); Console.WriteLine($"{(string)currentRow["Projekt"]}");
With an exit:
> Data that i want > Namespace.ExcelDataField > Data that i want
Where is ExcelDataField, I obviously have a class that I wrote to help me read data from an excel sheet. I tried to implement this so that it matches the DAO VBA access using MoveFirst / Next and always set 1 row of data (currentRow).
I used the ExcelDataField class to encapsulate data coming out of my excel sheet, because the data comes in as dynamic from an excel sheet.
public class ExcelDataField<T> { private Excel.Range m_XlRange; private int m_Row; private int m_Col; public T Data { get { return (T)(this.m_XlRange.Cells[this.m_Row, this.m_Col] as Excel.Range)?.Value2; } set { this.m_XlRange.Cells[this.m_Row, this.m_Col] = value; } } public ExcelDataField(Excel.Range range, int row, int col) { this.m_XlRange = range; this.m_Row = row; this.m_Col = col; } public static implicit operator T(ExcelDataField<T> dataField) { return dataField.Data; } }
I'm currently going for testing purposes that all data can be easily processed as a string, so that I do an overload of this ExcelDataField : ExcelDataField<string> class ExcelDataField : ExcelDataField<string> , which is the class that I use to read the Excel worksheet and just read it back to comfort .
Everything works fine until I use interpolated strings which obviously don't find my implicit conversion. I tried changing ExcelDataField : ExcelDataField<string > to ExcelDataField : ExcelDataField<string> , but both of them do not work.
In my understanding, interpolated strings use the FormattableString type, which has no implicit conversion from string or string only explicit.
My question could someone explain in more detail what exactly is happening here, and is there a clean way for me to use interpolated strings?