Skip to content

Commit

Permalink
Struct and Enum
Browse files Browse the repository at this point in the history
  • Loading branch information
XuanThuLab committed Aug 20, 2020
1 parent a4a4257 commit 5cdd957
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
27 changes: 27 additions & 0 deletions CS022_struct_and_enum/.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/struct_and_enum.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 CS022_struct_and_enum/.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}/struct_and_enum.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/struct_and_enum.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/struct_and_enum.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
26 changes: 26 additions & 0 deletions CS022_struct_and_enum/ProductStruct.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

namespace struct_and_enum {
public struct Product {

public Product(string _name)
{
name = _name; // đồng nghĩa khởi tạo thuộc tính Name
price = 100;
Description = "Mô tả về sản phẩm {name}";
}

public string name; // trường tên sản phẩm
public decimal price; // trường giá sản phẩm

// Phương thức sinh ra chuỗi thông tin
public override string ToString() => $"{name} : {price}$";

// Thuộc tính Name
public string Name {set => name = value; get => name;}
// Thuộc tính Description
public string Description {set; get;}

}

}
35 changes: 35 additions & 0 deletions CS022_struct_and_enum/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;

namespace struct_and_enum {

enum HocLuc { Kem, TrungBinh = 5, Kha, Gioi }

class Program {
static void test_enum () {
HocLuc hocluc = HocLuc.Kha; // khai báo biến hocluc kiểu enum và khởi tạo giá trị bằng HocLuc.Kha
switch (hocluc) {
case HocLuc.Kem:
Console.WriteLine ("Học lực kém");
break;
case HocLuc.Kha:
Console.WriteLine ("Học lực Kha");
break;
case HocLuc.Gioi:
Console.WriteLine ("Học lực Giỏi");
break;
default:
Console.WriteLine ("Học lực TB");
break;

}
}
static void Main (string[] args) {

Product product = new Product ("Samsung Abc");
Console.WriteLine (product.ToString ());

test_enum();

}
}
}
2 changes: 2 additions & 0 deletions CS022_struct_and_enum/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# struct và enum trong C#
https://xuanthulab.net/su-dung-cau-truc-struct-va-kieu-liet-ke-enum-trong-lap-trinh-c-c-sharp.html
8 changes: 8 additions & 0 deletions CS022_struct_and_enum/struct_and_enum.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>

0 comments on commit 5cdd957

Please sign in to comment.