C# Examples

C#, the fetus that C++ and Visual Basic .NET has given birth to. Watch these examples, and see how sexy this language is.
I learned this language in 20 minutes last night.
Variables:

static int Main() {
   int i;
   i=24;
   Console.WriteLine(i);
   return 0;
}
int i=24;
Console.WriteLine("i is equal to {0}",i);
string word="name";
string name="jakash3";
Console.WriteLine("My {0} is {1}",word,name);

If Statements:

Console.Write("Enter password: ");
string pass=Console.ReadLine();
if (pass=="123") {
Console.WriteLine("Password correct.");
} else if (pass=="penis") {
Console.WriteLine("Password too short.");
} else {
Console.WriteLine("Password incorrect.");
}

Loops:

int i;
for (i=0;i<21;i++) {
Console.WriteLine(i);
}
string input=null;
while (input!="exit") {
input=Console.ReadLine();
}
int i=0;
do {
Console.WriteLine(i);
i++;
} while (i<21);

Arrays:

int[] sizes=new int[3];
sizes[0] = 4;
sizes[1] = 7;
sizes[2] = 9;
Console.WriteLine(sizes[1]);
string[] people = { "jakash3", "joey", "sean", "kris" };
for (int i = 0; i < 4; i++) {
Console.WriteLine("people[" + i + "] = " + people[i]);
}
string[] languages = { "C/C++", "Assembly", "C#", "VB" };
foreach (string i in languages) {
Console.WriteLine(i);
}

Classes:

namespace ConsoleApplication1
{
    class Program
    {
        public class human
        {
            public string hair;
            public string eyes;
            public string skin;
            public void dosomething()
            {
                Console.WriteLine("The human did something...");
            }
            public int givenumber()
            {
                System.Random rand = new System.Random();
                int i = rand.Next(1, 10);
                return i;
            }
        }
        static void Main(string[] args)
        {
            human man = new human();
            man.eyes = "black";
            man.hair = "blue";
            man.skin = "green";
            man.dosomething();
            int randomnumber = man.givenumber();
            Console.WriteLine("The man came up with the number " + randomnumber);
            Console.ReadKey();
        }
    }
}

One thought on “C# Examples

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: