Received error "The best type for an implicitly typed array was not found"

This is my code for creating a Json response for jqGrid and for the new keyword to define a cell member. I get the following message "There is no better type for an implicitly typed array."

var resRows = results.Select(record => new { id = record.Reference, cell = **new** [] { record.Reference, record.TradeDate.ToShortDateString(), record.Currency1, record.Currency2, record.Notional.ToString(), record.EffectiveDate.ToShortDateString(), record.Quote.ToString() } }).ToArray(); 

What am I doing wrong here?

+6
source share
4 answers

Assuming Reference , Currency1 and Currency2 are strings, just declare it as a string array:

 var resRows = results.Select(record => new { id = record.Reference, cell = new string [] { record.Reference, record.TradeDate.ToShortDateString(), record.Currency1, record.Currency2, record.Notional.ToString(), record.EffectiveDate.ToShortDateString(), record.Quote.ToString() } }).ToArray(); 
+8
source

If you prepare the data for jqGrid (for example, in your code), you can define your own jsonReader and just skip the array of cells ( http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data ):

 jsonReader: { root: "rows", page: "page", total: "total", records: "records", repeatitems: false, userdata: "userdata" }, 

Then something like:

 var result = new { total = (int)count / grid.PageSize), page = grid.PageIndex, records = count, rows = results.Select(record => select new { Reference = record.Reference, TradeDate = record.TradeDate, .. }).ToArray() } 
+1
source

I had the same problem and I found that if all the data elements in the array are of the same type (String example), then the type was inferred and the compiler did not complain about the new [] .

0
source

If the members of the collection are functions, they still throw a compiler error. Even if the collection has only one function!

 var bads = new [] // COMPILER ERROR { Foo }; var goods = new Action[] // NO COMPILER ERROR { Foo }; //... public void Foo() { } 
0
source

Source: https://habr.com/ru/post/919238/


All Articles