Skip to content

Commit

Permalink
CS008_AnonymouType_Dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
XuanThuLab committed Aug 11, 2020
1 parent a4a4257 commit becdc19
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
27 changes: 27 additions & 0 deletions CS008_AnonymouType_Dynamic/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/CS008_AnonymouType_Dynamic.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
42 changes: 42 additions & 0 deletions CS008_AnonymouType_Dynamic/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/CS008_AnonymouType_Dynamic.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/CS008_AnonymouType_Dynamic.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/CS008_AnonymouType_Dynamic.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
8 changes: 8 additions & 0 deletions CS008_AnonymouType_Dynamic/CS008_AnonymouType_Dynamic.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
32 changes: 32 additions & 0 deletions CS008_AnonymouType_Dynamic/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;

namespace CS008_AnonymouType_Dynamic {
class Program {
static void Main (string[] args) {

// Tạo đối tượng kiểu Anonymous
var myProfile = new {
name = "XuanThuLab",
age = 20,
skill = "ABC"
};
Console.WriteLine (myProfile.name);

TestFunc(myProfile);



}

static void TestFunc (dynamic dvar)
{
// dynamic d1 = 7;
// dynamic d2 = "a string";
// dynamic d3 = System.DateTime.Today;
// dynamic d4 = System.Diagnostics.Process.GetProcesses();

Console.WriteLine (dvar.age); // ở thời điểm biên dịch - không biết dvar có thuộc tính age hay không, nhưng nó vẫn biên dịch
}

}
}
2 changes: 2 additions & 0 deletions CS008_AnonymouType_Dynamic/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Kiểu vô danh và kiểu động dynamic trong C# C Sharp
https://xuanthulab.net/kieu-vo-danh-va-kieu-dong-dynamic-trong-c-c-sharp.html

0 comments on commit becdc19

Please sign in to comment.