This question already has an answer here: Cast an Anonymous Types in Object and retrieve one Field 4 answers I want to read some lookup data from the database, using EF, so I do the following: public object LocationLookUps() { var locationTypes = Cli
I have the following code which I am trying to make work but it still does not compile. Thank you. List<Employee> emploees = new List<Employee>() { new Employee { ID = 101, Name = "Rosy" }, new Employee { ID = 102, Name = "Sury&
Having: Initialize an anonymouse collection (I would send it as json) var myCollection = new[] { new { Code = 0, Name = "", OtherAttribute = "" } }.ToList(); myCollection.Clear(); And get the data. myCollection = (from iPeople in ctx.P
Supposing I have the following anonymous type var g = records.Select(r => new { Id = r.CardholderNo, TimeIn = r.ArriveTime, TimeOut = r.LeaveTime, }); Is it possible to do something like the following: var g = records.Select(r => new { Id = r.Cardho
List<object> Students = new List<object>() { new { Name = "A", Age = 28, Height = 175 }, new { Name = "B", Age = 29, Height = 176 }, new { Name = "C", Age = 30, Height = 177 }, new { Name = "D", Age = 31
I am trying to return JSONified anonymous type from a WCF Service. I have been successful in doing so, but I am searching for a better alternative.. // In IService [OperationContract] [FaultContract(typeof(ProcessExecutionFault))] [Description("Retur
I'm making a query on a MethodInfo[] where I'm trying to find all the methods that have a return type of void, and has only one parameter of a certain type. I want to do it in the most minimalistic and shortest way. One way to do it would be: var val
Is there a way to build on to the select clause of a previously defined LINQ query? For example: var stuffQuery = from stuff in MyStuff select new { stuff.Name }; var query2 = from stuff in stuffQuery join otherStuff in YourStuff on stuff.Name equals
this is my code for example: var output = new { NetSessionId = string.Empty }; foreach (var property in output.GetType().GetProperties()) { property.SetValue(output, "Test", null); } It occurs an exception: "Property set method not found&qu
I've declare a anonymous list like this, and it contain list of contact also var ContactGroup = new[] { new { ContactGroupKey = 0, ContactGroupTLK = 0, Desc = "", Contacts=new List<object>() } }.ToList(); I try to check the list, if the Co
In my program I have many threads in a working state, started in the method run or by calling other method from run. What is the method to stop these threads? The threads are started as: Runnable r = new Runnable() { @Override public void run() { //
I'm trying to get a better understanding of Scala, and I can't seem to find a valid usecase for code like the following: class C extends { def m() { /* ... */ } } What is the rationale for allowing such constructs? Thanks!I guess the only rationale h
I was wondering if there exists a similar functionality in Java similar to C#'s anonymous types: var a = new {Count = 5, Message = "A string."}; Or does this concept go against the Java paradigm? EDIT: I suppose using Hashable() in Java is somew
How can I pass anonymous types as parameters to other functions? Consider this example: var query = from employee in employees select new { Name = employee.Name, Id = employee.Id }; LogEmployees(query); variable query here doesn't have strong type. H
Are there any tools that can generate classes from anonymous types? I have a complex data structure that I have created using anonymous types. I would like to use this data structure in other places where the anonymous type would be out of scope. Tha
I have a GridView where my DataSource is: items.Select(i => new { ID = i.ID, Foo = i }).ToList(); In the RowDataBound I want to access the object, but I don't know how to cast it... grid.RowDataBound += (s, e) => { if (e.Row.RowType == DataControlRo
I'm trying to get anonymous object from query: var myList = from td in MyObjectList select new { a = td.a, b = td.b, c = td.c, name = (from r in contex.NewList where r.aa == td.a && r.bb == td.b select r.Name).ToList() }; I would like name to have
This question already has an answer here: How to dynamic new Anonymous Class? 2 answers I wanna create an anonymous type that i can set the property name dynamically. it doesn't have to be an anonymous type. All i want to achieve is set any objects p
it's possible to return, from a method, an anonymous type list? I build my list of anonymous type like this var l = (new[] { new { Name = "thename", Age = 30 } }).ToList(); ThanksIt is possible if you return list that was cast to object, but it
I try to write some codes about Generate list from Anonymous type via below codes : public static List<T> MakeList<T>(T itemOftype) { List<T> newList = new List<T>(); newList.Add(itemOftype); return newList; } But ERROR return me:
In my plugin architecture I am currently passing a plugin name (string), method name (string) and parameters (object array) to my plugin service to execute the specified method and return the result (of type T). The plugin service's execute method ca
So I know that C++ is strongly typed and was just wondering if there was any library (or any thing for that fact of the matter) that would allow you to make a variable that has no initial specific type like var in Python.Take a look at boost::any and
What does var really do in the following case? var productInfos = from p in products select new { p.ProductName, p.Category, Price = p.UnitPrice }; var is a placeholder for a compiler-created ("anonymous") type that has three properties, Product
I have a LINQ statement that returns an anonymous type. I need to get this type to be an ObservableCollection in my Silverlight application. However, the closest I can get it to a List myObjects; Can someone tell me how to do this? ObservableCollecti
I have an asp:DetailsView with several columns, e.g. Foo, Bar. I want to fill it with an anonymous type, i.e.: gridView.DataSource = new { Foo = 1, Bar = "2" }; gridVeew.DataBind(); But getting next error: Data source is an invalid type. It must
C#: I have a collection of objects . T has 2 properties. Property A and Property B. The rule that this collection needs to adhere to is that the combination of values for A and B must be unique within the collection. In other words, A and B need to s
Is it possible in C# to create a System.Collections.Generic.Dictionary<TKey, TValue> where TKey is unconditioned class and TValue - an anonymous class with a number of properties, for example - database column name and it's localized name. Something
I'm trying to create a Fluent Interface to the Winforms Datagrid. This should allow me to use a typed datasource and easy use of properties of properties (Order.Custom.FullName) I'm adding the columns on initialization and trying to set the property
I looked online for some references but didn't have too much luck. Hopefully it's just some simple thing I'm overlooking, but in my code I'm looping through the participant list and storing the queried results into the array. As you can tell, my fore
Consider this: var me = new { FirstName = "John", LastName = "Smith" }; This is fine as we can then do this: Console.WriteLine("{0} {1}", me.FirstName, me.LastName); However we can't do this: public T GetMe() { return new { F