Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# alternative to tuple

I have a dbf file (dBase) that I want to read, put each row into a single list (since a row represents data about one shapefile object), and then be able to modify the list (e.g., convert fields which represent the name to a string). This means that the datatype need to be able to hold both Ints, strings, bool and so on, and add items to, it. In python I could do this with lists, but since sets cant be modified, I cant use them.

This sounds like a (exact) duplicate to Alternative to Tuples, but it isn't. These questions are based on the assumption that you know which objects you want beforehand; I don't.

I'm on .NET 4.5, btw.

like image 294
Rasmus Damgaard Nielsen Avatar asked Jun 22 '13 20:06

Rasmus Damgaard Nielsen


1 Answers

Use dynamic - it is a perfect use case for it:

Visual C# 2010 introduces a new type, dynamic. The type is a static type, but an object of type dynamic bypasses static type checking. In most cases, it functions like it has type object. At compile time, an element that is typed as dynamic is assumed to support any operation. Therefore, you do not have to be concerned about whether the object gets its value from a COM API, from a dynamic language such as IronPython, from the HTML Document Object Model (DOM), from reflection, or from somewhere else in the program. However, if the code is not valid, errors are caught at run time.

like image 135
Oded Avatar answered Sep 30 '22 00:09

Oded