C# - Are Anonymous Types Slower
Dec 30, 2010
Are anonymous types slower than declarative types?
For example, does
Dim score as Double = CalculateScore()
run slower than
Dim score = CalculateScore()
Why use explicit typing if it's no slower?
View 5 Replies
ADVERTISEMENT
May 5, 2011
VB2010: All, I am using a picturebox to show the constellation of GPS satellites, that starts out OK. I have to redraw every now and then, because if a dialog box gets drawn on top of it, the data doesn't refresh after the dialog box is closed. Same with moving the Frame around the screen, I have to redraw the picturebox. (not sure why, but I can live with that) When I first start the program and received data from the receivers and plot the Constellation the refresh/redraw is very quick, (just a flicker) then after about 30 mins or so the refresh seems to redraw the picturebox slower and slower. I can see the individual satellites (fillellipse) redraw.
Also, I have moved the picturebox into a TAB-frame. Even when I switch from on Tab to another, the picturebox will not refresh automatically. I have to do a clear and then replot the information.
View 10 Replies
Sep 5, 2009
Assuming Anonymous Types are tailored to be used with LINQ, I'd like to use them for simply and fast data aggregation without an explicit class definition, like in this snippet[code]....
View 2 Replies
Jun 29, 2009
I have a problem using linq and anonymous types in an asp.net vb.net application.When I write the code above, I have 2 errors :
- "declarations of variable with Option Strinct On requires an As clause"
- "the name 'item' is not declared"
Public Sub MyFunc(ByVal xe As System.Xml.Linq.XElement)
Dim lstitems = From it In xe.Elements Select txt = it.@Text, value = it.@Value
For Each item In lstitems
Dim s As String = item.txt
Next
End Sub
Does it mean that is not possible to use Option Strict On and Option Explicit On ?Or I make a syntax error ?Or is it just a bad configuration of my application ?
View 2 Replies
Mar 19, 2010
I would like to use reflection on an anonymous type resulting from a LINQ to SQL query. I know that reflection on anonymous types works in general. The following code successfully generates a propertyinfo array with two elements:
Dim MyObject = New With {.Col1 = 1, .Col2 = "Test"}
Dim t As Type = MyObject.GetType()
Dim pilist As PropertyInfo() = t.GetProperties
[Code].....
View 7 Replies
Jul 2, 2011
Supposing the referenced List below contains 2 elements:
Dim Countries = From c In List _
Select New With { .Country = c.Country, .CountryID = c.CountryID }
The code above returns
.Country=Spain .CountryID = 1
.Country=Spain .CountryID = 1
How can I get the distinct values? The Countries query should contain only
.Country=Spain .CountryID = 1
View 5 Replies
Feb 12, 2010
Instinctively, I would say that this is impossible, as NHibernate needs to know some mapping information on how to persist a given type. Thus, I encountered some situations in which I could use such a feature. For instance, through a named query or something like so. On the other hand, using a named query would require me to make an addition to the configuration file.
Let's suppose we have an application interacting with some underlying datastore. This datastore is configured through the NHibernate configuration file. Then, I wish to have NHibernate load only a subset of an entity properties, from another subsystem to which my application shouldn't need to interact much, so it is not worthy to define classes for this system, as I only need a fraction of this alien system's information, let's say three out of thirty-two data columns. For that matter, if I chose to load only those three columns let's say for performance concerns, I would then use an anonymous type, perform the required action onto this information, then persist it back to the datastore. Now, it wouldn't be of much interest to do so if I only had one entity to get loaded from the datastore, so let's say I have about 75,000 rows to load into my process. I then shall consider this subset option very seriously!
What strategy should you choose in such situation, if you needed to persist these changes to a subset only of this entity's properties?FYI: I am asking because I must write specific rules of usage with NHibernate, such rules that even a beginner developer would even be able to use it without knowing too much about NHibernate, but only following the rules and guidance of the technical documents I have to produce.
View 1 Replies
Mar 11, 2009
Any best approach to what I'm trying to achieve (linq to sql, returning list of data to show in a grid/list etc etc)... Its complaining about anonymous type conversion, and from what I'm reading, thats not elegant way of doing it.
Public Function GetHistory(ByVal historyId As Integer) As List(Of ?????????)
Using dc As New myDataContext(Application.GetConnection)
Return (From t In dc.ActionTypes, a In t.MyTable Where a.HistoryID = historyId Select a.ActionOn, a.ActionBy, t.Description, a.ImpactedItem, a.ActionDescription).ToList
End Using
End Function
View 4 Replies
Oct 25, 2011
I am in the process of learning LINQ to Objects. I am querying an array of reference elements using LINQ. In the code below, which I have marked with asteriks and PROBLEM, I am having difficulty returning any values for and I suspect its because of the multiple Select arguments.
'Program name:Querying an Array of Invoice Objects
'Created/revised:
'Project description:To demonstrate the use of LINQ to query objects
[Code].....
View 4 Replies
Jul 14, 2011
I was toying around with some of the linq samples that come with LINQPad. In the "C# 3.0 in a Nutshell" folder, under Chater 9 - Grouping, there is a sample query called "Grouping by Multiple Keys". It contains the following query:
from n in new[] { "Tom", "Dick", "Harry", "Mary", "Jay" }.AsQueryable()
group n by new
{
[Code].....
View 1 Replies
Jun 29, 2009
How to declare Anonymous types. I want to do a different query based on a condition.
Something like this:
If true then
Dim Myquery = From data In MyXML.Root.<hist> _
Select New With { _
.SensorID = CType(data.<sensor>(0), Integer)}
else
[CODE]...
Then I want to reference MyQuery outside of the condition. But how do I declare MyQuery outside of the if statement?
View 3 Replies
Apr 24, 2012
I've got the below, where I'm grouping a collection by a propery, then wanting to access the properties of my group. Problem I have is with the anonymous typing. Because of option strict I have to give an explicit type but I can't work out what the type should be. The below doesn't compile because t.HeadAccountKey isn't a value (as t has a type of object). So either I need do some casting or my linq selector is wrong,
[Code]....
View 1 Replies
Apr 24, 2012
The documentation has an example about grouping on multiple properties[code]...
Is it possible to rewrite the original query to just return IEnumerable(Of CustomerRegionGroup), or do I have to use the anonymous type, and run a second query on the result of the first?
View 1 Replies
Jul 26, 2010
I'm trying to create a web site that users can log into and self serve their user information ie name, address etc. I've set up a SQL server DB with a couple of table holding the data and accessing those using Linq. I'm selecting specific data from my datacontext then trying to assign it to a label, ideally I want to assign the value to a class attribute so I can use the users details on multiple pages.
I've simplified the code (removing WHERE statement etc for the purposes of this question):
Using CurrentUserDataContext
As
New UserDataDataContext()
[Code].....
View 2 Replies
Jun 29, 2010
I'm trying to translate some C# LINQ code into VB.NET and am stuck on how to declare an anonymous type in VB.NET.[code]How do you translate C#'s new { ... } syntax into VB.NET?
View 2 Replies
Mar 17, 2010
Every LINQ example I have seen for VB.NET anonymous types claims I can do something like this:
[code]...
Now when I go to iterate through the collection(see example below), I get an error that says "Name "x" is not declared. For Each x in Infos It's like VB.NET doesn't understand that Infos is a collection of anonymous types created by LINQ and wants me to declare "x" as some type. (Wouldn't this defeat the purpose of an anonymous type?) I have added the references to System.Data.Linq and System.Data.DataSetExtensions to my project. Here is what I am importing with the class:
[code]...
View 4 Replies
Mar 31, 2012
My c++ app (which has both managed and unmanaged dlls) loads very slow ( > 70 sec) during first time startup. After that it takes 20 sec only during startup. Why? How to make it faster always?
I tried with /Delayloading, rebase etc. It did not give much improvement. In fact after rebase it took more time. note that my app has more than 150 dlls
View 3 Replies
Feb 29, 2012
I have spent years writing VBA code that has got increasingly complicated. For the first time, I came across the error in VBA "Out Of String Space" when dealing with a 200MB CSV file.To overcome this I copied and pasted all the code over to VB.NET, compiled changed a few errors and ran the new code. The VB.Net takes 15mins, when VBA took 3 mins.For instance,Previously, to read the contents of the CSV file in VBA I used the code,Dim whole_str As String
Open file_path for Input As #1
whole_str = Input$(LOF(1),1)
Close #1
[code].....
View 1 Replies
Jul 9, 2009
I'm a Linq noobie, maybe someone can point me in the right direction. What's wrong here? These anonymous types seem to have the same signatures.
[Code]...
View 2 Replies
Aug 3, 2009
I converted some code from vb6 to vb2005 that opens a recordset and populates a listbox
with about 8,000 names. It uses classic ado. The vb6 code does it in about 0.75 of a second, the first vb2005 code does it in about 5.5 seconds while the second vb2005 code does it in about 4.5 seconds. Is there any way to improve the vb2005 performance a fair bit more?
[Code]...
View 2 Replies
May 17, 2010
I'm upgrading to VB2008 from VB6 and have noticed that when drawing a small diagram on the screen it is much slower. In VB6 is is drawn 'instantly' in VB2008, 34 lines, 5 arcs and 15 text items are taking 112000,000 ticks to draw- I can see it being drawn line by line. The codes contains the code to draw the diagram and some minor calculations to determine what to draw. If I just draw 4 lines directly it takes 80,000 ticks which looks 'instant'. It looks as if the calculations are slowing it down. Is there some reason for this, is there a box I have not ticked that makes it slow?
View 7 Replies
Nov 1, 2009
I have a class with a Property called 'Value' which is of type Object.Value can be of any type, a structure, a class, an array, IList etc.My problem is with the setter and determining whether the value has changed or not.This is simple enough for value types, but reference types and lists present a problem.For a class, would you assume that the Equals method has been implemented correctly, or just assume that the value has changed every time the setter is called?If I did assume it's changed, then perhaps I should assume it for value types as well, so that the behaviour is consistent.
View 2 Replies
Jun 23, 2012
I need to compare two dictionary values if the types stored are equal, this is what i have
if gettype(Args(key)) = gettype(argtypes(key)) then
'' do something
end if
[Code]....
View 1 Replies
Sep 14, 2010
I have a function where I am performing a lot number of database operations inside a Sub. The operation when called directly like:ExecProcess()
takes about 11 seconds to run.However, if I create a Delegate, and call the sub using BeginInvoke(), the very same process takes over 40 seconds to execute.Here's the threaded code:
Protected del As ProcessDelegate
Protected Delegate Sub ProcessDelegate()
del = New ProcessDelegate(AddressOf SELocal.ExecJob)
Dim cb As New AsyncCallback(AddressOf Me.ExecJobComplete)
del.BeginInvoke(cb, del)
Anyone know what may cause a function to take longer inside a new thread, rather than calling directly?
View 2 Replies
May 12, 2010
Is VB Express 2010 slower to compile and run that older versions of VB Express? I've installed it this weekend and it seems a little sluggish on my quad core computer with 1 gig of RAM. I have VB Express 2005 installed for my students at school and it seems to fly just fine. Those school computers are older P4s with 512k of RAM.
View 7 Replies
Sep 1, 2009
I have a client who needs Excel VBA code that produces formula values moved to VB.NET. He is in the business of providing financial analytics, in this case delivered as an Excel add-in. I have translated the VBA into VB.NET code that runs in a separate DLL. The DLL is compiled as a COM Server because, well, Excel-callable .NET UDFs have to be. So far, so good: Excel cells have "=foo(Range1, Range2, ...)", the VB.NET Com Server's UDF is called, and the cell obtains a value that matches the VBA code's value.
View 7 Replies
Sep 24, 2011
I am sure i am doing something terribly wrong, but i should better ask the experts.
At the third line i get the error Value of type <anonymous type> cannot be converted to <anonymous type>
Dim Query = (From c In Db.web Select New With {.AA = c.AA}).ToList
Dim v = New With {.Amount = 108}
Query.Add(v)
View 2 Replies
Mar 13, 2011
The following syntax is valid VB.NET code
Dim myCollection As New List(Of Stock)
myCollection.Add(New Stock(Guid.NewGuid, "Item1"))
myCollection.Add(New Stock(Guid.NewGuid, "Item2"))
[code]....
How can I accomplish the same thing in C#? I have tried...
myCollection.FindAll(bool delegate(Stock stock) {
if (blah blah) {
}
});
But it appears I have somehow structured it incorrectly as I get the following error. "Error 1 Invalid expression term 'bool'"
View 3 Replies
Jun 28, 2010
I have below code in C#:
[Code]...
View 3 Replies
Feb 12, 2010
I am trying to figure out how to get at an anonymous typed object's properties, when that anonymous type isn't created in the current function.
Specifically, I am binding an ASP.NET ListView to LINQ resultset, then trying to process each item in the ItemDataBound event.
Option Explicit On
Option Strict On
Class MyPageClass
[Code]....
View 3 Replies