Skip to content

Instantly share code, notes, and snippets.

View Muhammad-1990's full-sized avatar
💭
eat sleep code repeat

Muhammad Ahmod Muhammad-1990

💭
eat sleep code repeat
  • NovationTechnologies
  • Cape Town, South Africa
  • 03:06 (UTC +02:00)
  • LinkedIn in/muhammad-ahmod
View GitHub Profile
@Muhammad-1990
Muhammad-1990 / TupleDeconstruction.cs
Created July 12, 2024 01:06
You can simplify method outputs by returning multiple values using tuples and deconstruction. The following example shows how to implement a tuple with 3 return items and how to discard unwanted returns.
namespace TupleDeconstruction;
public class Program
{
public static void Main()
{
// When deconstructing you can use _ to discard unwanted variables.
var (Status, _, Reason) = WorkflowProgress.GetPaymentProgress("PMT_01J17CQ41K2Y0D5C3D8VG8");
// Status: ProvisionallyAccepted
@Muhammad-1990
Muhammad-1990 / DataMask.cs
Last active July 11, 2024 22:54
You can extend built in functionality in the form of an extension method to provide consistent way of accessing a feature. The following example shows how to override the toString method and take advantage of built in string functionality in the form of an extension method.
namespace DataMask;
public class Program
{
public static void Main()
{
var creditCard = new CreditCard()
{
NameOnCard = "Muhammad Ahmod",
Pan = "1234 5678 6787 2332",
@Muhammad-1990
Muhammad-1990 / ObjectInitializer.cs
Last active July 10, 2024 13:13
You can use object initializers to initialize type objects in a declarative manner without explicitly invoking a constructor for the type. The following example shows how to use object initializers with named objects.
namespace ObjectIntitializer;
public class Program
{
public static void Main()
{
// Initialize objects by using an object initializer.
var currency = new Currency { Id = 128, Code = "ZAR", Name = "Rand", Country = "South Africa" };
// Id = 128, Code = ZAR, Name = South Africa, Country = South Africa