Skip to content

Instantly share code, notes, and snippets.

@tuannguyenssu
Last active July 7, 2019 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuannguyenssu/de5d4a6c323a476c8b98511a7f59b5c7 to your computer and use it in GitHub Desktop.
Save tuannguyenssu/de5d4a6c323a476c8b98511a7f59b5c7 to your computer and use it in GitHub Desktop.
// Class này chứa cả thông tin và các phần xử lý
public class Student
{
public string Name { get; set;}
public int Age { get; set;}
// Format class này dưới dạng text, json để in ra
public string GetInfoText()
{
return "Name: " + Name + ". Age: " + Age;
}
public string GetInfoJson()
{
return Json.Serialize(this);
}
// Lưu trữ xuống database, xuống file
public void SaveToDatabase()
{
dbContext.Save(this);
}
public void SaveToFile()
{
Files.Save(this, "fileName.txt");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment