Sunday, November 1, 2015

C# What are try, catch and finally

Its pretty simple again as the name suggests, 



Remember you shouldn't use a try catch block if you don't expect any errors in the first place

An example of try catch finally would be this;



     try
        {
            int a = 10;
            int b = 20;
            int z = a + b;
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
        finally
        {
            Console.WriteLine("Executed");
        }

C# What are access modifiers

People I know C# can be intimidating at once but Access Modifiers is  a self-explanatory term innit ? I' mean access = permission to enter, modifiers = 1/0 (if one = access granted, 
0 = access denied). Lets view some graphic,




Many programmers prefer to use public methods so that its like always an open gate, kinda flexible and anyonem anything can access it, without any hassle.

Now, when i was first learning C# I used to search for ebooks, videos on youtube and even forums like stackoverflow they used to mention about like yea try changing your access modifier and I was like before going further I wanna find out what access modifiers are in the first place.

Here's an example; (view fullscreen click here)

C# what does static mean

C# can be intimidating and consists of several terms which addup to the pile of shit and one such term is static you've mostly seen it in "public static void main";

Best way to remember what it means is to remember it as a magic word which will allow you to access any method in any class without creating an instance of class.


To explain this I'll be creating a fun and simple program which will shout out your name back to you, its more fun cuz it'll shout back whatever you enter =D

In visual studio after you've created a new console application create a new class called shoutout.cs 



Now here I'll be showing you two examples one with static and one without static, so that you finally get to know the difference, (view in Fullscreen Click Here)






C# what is main