Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

ExpandoObject Syntax that Compile

//The code that will compile will look like this:
dynamic cust = new ExpandoObject();
cust.FullName = "Peter Vogel";

// lambda expression doesn't return a value but does accept a single parameter of type string,
// expression needs to be cast as an Action<string> type, like this:
// Note: Inside the lambda expression, if you want to work with a property on the local variable (as I do here), 
// you must refer to the variable that's holding your method. 
// Omitting that reference or using the this keyword won't work.
// Either way, you'll end up referring to the class that this code is inside of, 
// not to the ExpandoObject that the lambda expression is being added to.
cust.ChangeName = (Action<string>) ( (string newName) =>
            {
                cust.FullName = newName;
            } );

// Here, for example, is the code to call my ChangeName method:
cust.ChangeName("Jan Vogel");

// This variation on my ChangeName method accepts a string parameter and returns an integer value, 
// so its Func declaration is Func<string, int>:
cust.ChangeName = (Func<string, int>) ( (string newName) =>
            {
                cust.FullName = newName;
                return cust.FullName.Length;
            } );

            
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity blender shadow messed up 
Csharp :: C# replace all . except last one 
Csharp :: c# text editor 
Csharp :: c# linq aggregate string builder 
Csharp :: esaddex34 
Csharp :: c# open config file by path 
Csharp :: Get the Default gateway address c# 
Csharp :: what is C# 
Csharp :: spreate by captial char in c# 
Csharp :: c# linq where value is max and one item 
Csharp :: dotnet target specific framework 
Csharp :: ExceptionFilterAttribute exception-handler-middleware-not-catching 
Csharp :: and in c# 
Csharp :: ASP.NET Core set update clear cache from IMemoryCache (set by Set method of CacheExtensions class) 
Csharp :: isdaylightsavingtime in c# 
Csharp :: Cursor Invisibility 
Csharp :: Open Windows Explorer to a certain directory from within a WPF app 
Csharp :: identity-1.us-south.iam.test.cloud.ibm.com:443 
Csharp :: C# string go to line 
Csharp :: screenshot c# WinForms 
Csharp :: unity shader show object behind object 
Csharp :: wpf line intersect rectangle 
Csharp :: list remove positions c# 
Csharp :: unity transform.translate 
Csharp :: unity overlapspherenonalloc 
Csharp :: change object material unity 
Csharp :: asp net core send email async 
Csharp :: Unity inverse kinematics nothing is happening 
Csharp :: a infinite loop in text box update ui c# 
Html :: font-awesome envelope 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =