File tree 2 files changed +43
-0
lines changed
2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+
3
+ class ActionDemo
4
+ {
5
+ static void Main ( string [ ] args )
6
+ {
7
+ // 1. Using a named method
8
+ Action namedMethodAction = NamedMethod ;
9
+ namedMethodAction ( ) ;
10
+
11
+ // 2. Using an anonymous method
12
+ Action anonymousMethodAction = delegate
13
+ {
14
+ Console . WriteLine ( "Anonymous Method Action" ) ;
15
+ } ;
16
+ anonymousMethodAction ( ) ;
17
+
18
+ // 3. Using a lambda expression
19
+ Action lambdaAction = ( ) => Console . WriteLine ( "Lambda Action" ) ;
20
+ lambdaAction ( ) ;
21
+
22
+ // 4. Using Action with parameters
23
+ Action < int , string > actionWithParams = ( num , text ) =>
24
+ Console . WriteLine ( $ "Number: { num } , Text: { text } ") ;
25
+ actionWithParams ( 10 , "Hello" ) ;
26
+ }
27
+
28
+ // named method used for first Action instance on line 10
29
+ static void NamedMethod ( )
30
+ {
31
+ Console . WriteLine ( "Named Method Action" ) ;
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ <Project Sdk =" Microsoft.NET.Sdk" >
2
+ <PropertyGroup >
3
+ <OutputType >Exe</OutputType >
4
+ <TargetFramework >net8.0</TargetFramework >
5
+ <EnableDefaultCompileItems >false</EnableDefaultCompileItems >
6
+ </PropertyGroup >
7
+ <ItemGroup >
8
+ <Compile Include =" action.cs" />
9
+ </ItemGroup >
10
+ </Project >
You can’t perform that action at this time.
0 commit comments