Skip to main content


Showing posts from March, 2018

C# Fundamentals - Lambda Expressions

Lambda Expressions - Introduction Lambda expressions are how anonymous functions are created. It's a very powerful syntactic sugar that is available in C#.
At syntax level,The lambda operator => divides a lambda expression into two parts. The left side is the input parameter and the right side is the lambda body.
 A lambda expression can be simply viewed as a function or method without name, which looks like method parameter(s) => method body, or method parameter(s) => method return value. The => operator is called lambda operator and reads “go to”.
 In order to get a grasp of how lambdas work we will go through some examples.
Simple Lambda Example using System; using System.Collections.Generic; using System.Linq; public static class BitShift { public static void Main() { List<int> list = new List<int>() { 10, 12, 13, 14, 15, 16 }; List<int> evenNumbers = list.FindAll(x => (x % 2) == 0); …

Unity C# Attributes

Attributes Used In Unity An attribute is a declarative tag that conveys information about the behaviors of various elements like classes, methods, structures, enums etc. in the program.
An attribute is depicted by square ([ ]) brackets placed above the element it is meant for.
Attributes are used for adding metadata, such as information such as comments, description, methods and classes to a program. The .Net Framework provides two types of attributes: the pre-defined attributes and custom built attributes.
Syntax for specifying an attribute:
[attribute(positional_parameters, name_parameter = value, ...)] element We will go over the pre-defined attributes on another post.
For now let's go over the most useful custom attributes that Unity has, as you now have a basic knowledge of what attributes are.
DisallowMultipleComponent: Prevents the same component from being added to the same game object.
[DisallowMultipleComponent] public class PlayerControl : MonoBehaviour { ..... ....…

C# Naming Conventions

C# Naming Conventions Naming conventions are a often overlooked part of writing code. They are rarely taught to beginners often times because it can be considered as a dry and drab part of writing code. The same can be said about writing good comments in a program. Good practices while writing comments will be covered in the future.
Back to Naming Conventions.
They exist to help you and others to navigate your code and they also prevent a lot of common mistakes and pitfalls.
We will now go over the most common naming conventions that exist.
Pascal Case : All starting letter of each word is capitalized.Camel Case : All starting letters of each word is capitalized except for the first word.Snake Case : Each word is separated by an underscore. It can be upper or lower case.*Note : In some circumstances each of these will be slightly modified.
Pascal Case - Places To UseNamespaces : eg - namespace BitShiftProgrammer.Tutorial{....}
Classes : eg - class PlayerControl
Public Fields : eg - publi…

Assets Worth Checking Out