C# – Framework Design Guidelines

BEST PRACTICE

Returns
1. NULL Returns
– When returning a collection or enumerable ALWAYS return an empty enumerable/collection

String
1. String Concatenation
– Use StringBuilder instead of String concatenation
– string concatenation creates new memory allocation for new string
– stringBuilder uses the same memory
2. Always use string.IsNullOrEmpty() and string.IsNullOrWhiteSpace() whenever possible

LINQ
1. WHERE() with FIRST()
– Avoid using WHERE and First together or First when you are unsure that the result can be null.
– Use FirstOrDefault() where ever possible

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {       
            //INCORRECT
            List numbers = new List{1,4,5,8,11,14,20,21,25,34,40};
            int firstEven = numbers.Where(x => x % 2 == 0).First();
            Console.WriteLine("First Even number : {0}", firstEven);
            
            //CORRECT
            int firstEvenCorrect = numbers.FirstOrDefault(x => x % 2 == 0);
            Console.WriteLine("First Even number : {0}", firstEvenCorrect);
        }
    }
}

Casting
1. Cast by “as (T)” instead of “(T)”

As (T) (T)
Returns null when casting is not possible Prefix casting will throw exception
Can be applied to reference type variable only Prefix is free for all
Cannot perform user-defined conversions Prefix can perform User defined conversion
//INCORRECT
var dog = (Dog)animal;

//CORRECT
var dog = animal as Dog;

Exceptions
1. Re-throwing exceptions

//INCORRECT 
throw ex;

//CORRECT
throw;

Enumerations
1. Use FOR LOOP for non collection eg array
2. Use FOR EACH for collection
3. Do not use OrderBy before Where clause

Keywords
1. Avoid using “ref” and “out” keywords as much as possible

Class
1. Always use properties instead of public variables

Sago

Sago

Names: Sago, sago palm, sago pearls
Hindi: Sabudana

sago palm tree
sago palm tree

What is Sago?
Sago is produced from sago palm, it is the starch extracted from the center of sago palm stems, then processed into small, circular pellets referred to as pearls.

For Vegan:
– Good source of protein.

Glycemic Index
– High GI food: recommended to take in low amount if you are a diabetic.

How is Sago Used?
– Sago is popular in Indian recipes
– Included in tea popular in Asian drink
– Included in desserts and breads
– Can combined with rice for light and low calorie meal
– Thickening foods such as gravy or sauces
– Powder form for flour substitue

- Sago is high in carbohydrate content.
- A 100-gram serving contains nearly 86 grams of carbs.

- 100 grams of sago contains less than 1/2 gram of protein

- Sago contains a very low amount of total and saturated fat.
- A 100-gram serving has only .2 gram of total fat and .1 gram of saturated

- Not a low calorie food
- A 100-gram serving of sago yields for 350 calories

- A 100-gram serving gives you 7 percent of your daily allowance.
- Contains small amounts of calcium, copper, potassium and sodium.

Health benefits:

1. Aid in digestion

2. Nutritional value: a source of pure carbohydrates with very little protein, vitamin C, calcium and minerals.

3. A high energy booster:
– Energy-boosting ingredients in soups, puddings, smoothies, side dishes and main courses. It is a good substitute for energy supplements.

4. You can gain weight quickly by eating sago.

5. Enhance joints and bone health
– It helps to improves the joints and bones because it has minerals like calcium, iron, etc. Sago has Glucosamine which boosts the bone density, flexibility and joint movements. It also increases the amount of synovial fluid which is responsible smooth movement of joints.

6. Controls Hypertension
– 100g of sago contains around 5mg of potassium. Potassium helps to improve blood circulation and one of the best to cure hyperternsion. It stimulates healthy blood flow which decreases the strain on cardiovascular system

7. Helps in Muscle growth
– Sago has a good source of protein which aid in growth of muscles and strengthening. Also helps in faster recovery of function cells.

sago_pearl
Sago Pearl