.net - Anonymous Functions In C#?

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


ADVERTISEMENT

VS 2008 : Have A Class Where The Functions Of The Same Name Are Both Instance Functions And Shared Functions?

Dec 6, 2010

What I am trying to do is have a class where the functions of the same name are both instance functions and shared functions.

Public Shared Function Get...(byval xx as xx)

and

Public Function Get...

The Public Function uses a Property xx created in the constructor, whereas the Shared Function has the parameters (byval xx as xx).

View 1 Replies

.net - Linq, VB - Anonymous Type Cannot Be Converted To Anonymous Type?

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

Excel Maths Functions And Calls To All DLL Functions Documentation?

Jan 29, 2007

1) Is it possible to access the Excel mathematical functions without actually opening Excel?

I was thinking of through a DLL WinAPI call or maybe a delegate function or smaller program?

2) Does anyone know of a MS link or area that gives instruction on "how to" use every function of every Windows DLL at all?

Or for all those that Microsoft have chosen to document online at least.

View 1 Replies

Differences Between VB Functions And Convert.To* Functions?

Feb 19, 2009

While converting types, I have found myself using both VB functions and BCL Convert.To* methods.
E.g.)

Cstr() vs. Convert.ToString()
CInt() vs. Convert.ToInt32()
CDbl() vs. Convert.ToInt64()
etc...

Are there any subtle differences that should be noted?

View 1 Replies

[2005] MembershipUser Functions - See Exactly What The Functions Are Doing?

Mar 4, 2009

Is there a way to see exactly what the functions are doing. What i mean is there a way to see the class? I know what it does, i just want to know the code.
For example the function: Membership.FindUsersByName()

View 1 Replies

Value Of Type <anonymous Type> Cannot Be Converted To <anonymous Type>

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

Anonymous Delegate From C#

Jun 28, 2010

I have below code in C#:

[Code]...

View 3 Replies

Create Functions In Functions

Jul 1, 2011

I'm redoing a program for my company and my boss wanted me to created the entire thing through functions...

For the task I wanted to know is it possible to have functions within functions?
Sort of like in C where we would have nested structures?

Its a FILE I/O, with robot commands, moves and verifications....

So I would find the line in an excel spreadsheet where it moves, the coordinate, put it into an array.

Take the actual results store them into a two dimensional array...etc, etc....

Another function would eventually compare the results with the moves, and within a tolerance.

View 9 Replies

.net - Get Properties From Anonymous Type?

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

Anonymous Delegate Translation From C#?

Dec 23, 2008

I have a problem in translating a piece of C# code

(
http://www.codeproject.com/KB/WPF/VMCommanding.aspx)static bool ConfigureDelayedProcessing(DependencyObject depObj, ICommandSink sink) { bool isDelayed = false;

[code]....

View 7 Replies

Anonymous Methods In .NET - Foreach?

May 16, 2011

I try to replace the classic For Each with the LINQ ForEach method in VB.NET

Dim singles As New List(Of Single)(someSingleList)
Dim integers As New List(Of Integer)
For Each singleValue In singles

[code]....

How should I correctly do it (using anonymous methods = without declare a new function)?

View 2 Replies

C# - Anonymous Class Initialization In .Net?

May 11, 2009

i want to create an anonymous class in vb.net exactly like this:

[Code]...

View 2 Replies

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

Convert Anonymous Method To .NET?

Mar 20, 2012

I have the following in C#: public static void StartAnimation(UIElement animatableElement, DependencyProperty dependencyProperty, double toValue, double animationDurationSeconds, EventHandler completedEvent)

[Code]...

View 2 Replies

Convert C# Anonymous To Program?

Mar 26, 2011

Convert this below code to vb.net. I have no idea to convert from anonymous method to vb.net. I'm currently using VS2010.[code]...

View 4 Replies

GetCustomAttributes On An Anonymous Delegate?

Dec 14, 2010

I am struggling to retrieve custom attributes from a method. As you can see, the method ProcessXML has a custom attribute. The method itself gets passed into an anonymous delegate and then, in that context, I'm looking to get its custom attributes, but I'm not sure quite how to do it.

Here's my code

Public Sub UpdateXML()
Dim errors = New Errors
Dim xml = <testxml>

[code]....

View 1 Replies

How To Call Anonymous Objects

Jun 22, 2010

was trying to call a different and Anonymous objects into my form but i can't reach to the right method tyo do that my matter here is falls under calling a tree view.... i mean any tree view !!!

[Code]...

View 5 Replies

How To Create Anonymous Method

Jan 25, 2012

There are two ways to create methods on the fly. Through Anonymous method and through Lambda expression (relevant for C# language as far as i know). Though there is not much difference between them. How to create Anonymous methods in VB.NET ?

View 1 Replies

Lambda - Anonymous Delegates In .net (pre Vb9)?

Apr 7, 2009

Is it possible to create anonymous delegates in vb.net version 8 or earlier? If so, could someone provide an example of the syntax?

View 2 Replies

Linq Using Anonymous Type

Nov 12, 2009

Why did the anonymous type property "Points" still have the value "0"? [code]

View 1 Replies

Return And Use An Anonymous Types?

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

Serialize Anonymous Type To Xml

Oct 7, 2010

In MVC I can do something like the following to serialise an object with an anonymous type to JSON.[code]I'd like to do exactly the same but output xml. I haven't been able to find an equivalent method. Would someone please point me in the right direction?

View 2 Replies

Set Anonymous Type For IEnumberable?

Dec 1, 2010

I need to Convert a Ienumerable to a dataset. For this i need to write a common fnction to convert any IEnumberable type to Dataset. For this I need to set anonymous type.[code]...

View 1 Replies

Use Anonymous Delegate Instead Of AddressOf

Jul 16, 2010

Is it OK to use anonymouse delegates instead of AddressOf?

[Code]...

View 2 Replies

Using Linq And Anonymous Types?

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

.net - Extension Method For Anonymous Function?

Jul 13, 2011

I'm trying to create an extension method that returns an IEqualityComparer based on a lambda function. Heres the extension method:

<Extension()>
Public Function Comparer(Of T)(Func As Func(Of T, T, Boolean)) As IEqualityComparer(Of T)
Return New GenericComparer(Of T)(Func)
End Function

[Code]...

View 1 Replies

.net LINQ Xml Query - Anonymous Type?

Oct 22, 2009

I'm out of my depth populating a windows form from an XML linq query (see code further down in post). The listbox is populated as intended, when a value is selected (row) I would like to populate the remaining form controls. The linq query I believe has created a new datatype "Anonymous Types". The query is only local to the load form subroutine but I'm not sure how to make it global.

When I define the query simply as an object the code in the selectedValueChanged event can't execute due to late databinding. how I can initially load the listbox from linq xml query and then populate the other controls when the value changes? Am I right in thinking even though the listbox is multi-columns (property) you can ONLY ever reference a row and NOT a column? I'm new to LINQ and Anonymous Types and the more I read the more confused I seem to get. On a less important note the order by is not functioning as intended (no errors) but data is always retrieved in xml file order and not by the node <text>. Also looked at using <text>.first to order the results without success.

[Code]...

View 5 Replies

Addhandler - Use RemoveHandler & Anonymous Methods?

Sep 16, 2011

How do I use RemoveHandler with anonymous methods? This is how I add a handler for MyEvent event of the class MyClass

AddHandler MyClass.MyEvent, Sub()
...
End Sub

How do I then use RemoveHandler to remove the handler for the MyEvent event

View 1 Replies

Anonymous Object Initializate Syntax?

Apr 8, 2010

What is wrong with this Anonymous Object Initialize syntax?

If (Not row Is Nothing) Then
Dim info As New CultureInfo(Conversions.ToString(row.Item("cultureId"))) With { _
.NumberFormat = New With {.CurrencySymbol = Conversions.ToString(row.Item("symbol")), _

[code].....

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved