Search code examples
c#.net

Google Sheets API Response IList object to String in C#


static string StringEntryRequest()
    {
        var range = "NET!A1";
        var request = service.Spreadsheets.Values.Get(spreadsheetId, range);
            Console.WriteLine("Execute");
        ValueRange response = request.Execute();
            Console.WriteLine("Execute complete");
        IList<IList<Object>> values = response.Values;
            string i = values.ToString();
        return (i);
    }

I have created a Application in C# which should return the Value of a Cell in a Spreedsheet. The Problem is that i can't convett the IList Object into a String. My Current code works fine but just the conversion from IList to String seems impossible to me.


Solution

  • I found a way to convert the given IList into a String with the following Method:

            foreach (var value in values)
            {  
                string i = value[0].ToString();
                return i;
            }
    

    But as Joel points out in a comment,

    return values[0][0].ToString();
    

    is easier and less code.