Skip to content

Commit

Permalink
Type
Browse files Browse the repository at this point in the history
  • Loading branch information
XuanThuLab committed Aug 20, 2020
1 parent a4a4257 commit aa08d7d
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
27 changes: 27 additions & 0 deletions CS025_Type/.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/CS025_Type.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 CS025_Type/.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}/CS025_Type.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/CS025_Type.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/CS025_Type.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
8 changes: 8 additions & 0 deletions CS025_Type/CS025_Type.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 CS025_Type/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Reflection;

namespace CS025_Type {
public class A {
public int ID { get; set; }
public string Name { get; set; }
}

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

A a = new A {
Name = "HOTEN",
ID = 10
};

//Lấy tên và giá trị các thuộc tính có trong a
foreach (PropertyInfo property in a.GetType().GetProperties())
{
string property_name = property.Name; // Lấy tên thuộc tính
object property_value = property.GetValue(a); // Đọc giá trị thuộc tính đối tượng a
Console.WriteLine($"Thuộc tính {property_name} giá trị là {property_value}");
}
}
}
}
/*
Kết quả:
Thuộc tính ID giá trị là 10
Thuộc tính Name giá trị là HOTEN
*/

0 comments on commit aa08d7d

Please sign in to comment.