KamranCSharp - whereIstand.com

Thursday, December 4, 2008

Chapter 3: Encapsulation


Encapsulation
The notion of encapsulation programming logic is the idea of data hiding.
Using accessor and mutator methods we can make encapsulation, or by using properties.
ENCAPSULATION USING PROPERTIES:
Properties are a new feature introduced with C#. Properties in C# helps to protect a field in a class by reading and writing to it. Encapsulation can be accomplished much better with properties. Now let's see an example:

public class Department
{
private string departname;
public string Departname
{
get
{
return departname;
}
set
{
departname=value;
}
}
}
public class Departmentmain
{
public static int Main(string[] args)
{
Department d= new Department();
d.departname="Speaking";
Console.WriteLine("The Department is :{0}",d.Departname);
return 0;
}
}



Monday, December 1, 2008

Chapter 3: Conditional & Switch Statements

The if & else if statement

Conditional statements allows us to test to see if a specific condition is met.

static void Main(string[] args)
{
Console.WriteLine("Type is a string");
string input;
input = Console.ReadLine();
if (input == "")
{
Console.WriteLine("You typed an empty string");
}
else if (input.Length < 5)
{
Console.WriteLine("The string had less then 5 characters");
}
else if (input.Length < 10)
{
Console.WriteLine("The string has at lease 5 but less" + "then 10 characters");
}
Console.WriteLine("The string was " + input);
}

Now, there is absolutely no limit as to how many times you have to use " else if" that is entirely upto you. This exam is as simple as possible, so now lets move to something more fun...

The Switch statement

Another form of selection statement is the wwitch statment. It allows you to handle the program flow. When using this also note that case values are constant, variables are not permitted. Follow the example below on the console application to get more of handon to better understand. It's simple as self explanatory.


class Program
{
static void Main(string[] args)
{
Console.WriteLine("1 [C#], 2 {VB.NET]");
Console.Write("Pick your choice: ");
string choice = Console.ReadLine();
int n = int.Parse(choice);
switch (n)
{
case 1:
Console.WriteLine("C# is a great powerfull language");
break;
case 2:
Console.WriteLine("VB.NET is a really forgiving language");
break;
}
}

Chapter 3: Programming Basics / C# Iteration Constructs

C# Iteration Constructs

Almost all programming languages I have worked with will have your simple for loop, foreach statments. So, this is just something to practice little on, we will not spend too much time on it:

for loop
foreach / in loop
while loop
do/while loop

We will now examine these looping construct in a new console application.

for Loop

With for loop you can iterate over a block of code with a fixed number of times. That being said, you are able to specify how many times a block of code repeats itself.

One of the short cut to get a for loop statement, without even typing any code is to right click, select "Insert Snippit", then select "for", then customize your for loop. Also instead of writing out "console.wrieline", you may type "cw" then hit tab twice.


for (int i = 0; i < 3; i++)
{

Console.Wireline("Your number is: {0} ", i);
}

foreach Loop

C#'s foreach keyword allowes you to iterate over all items within an array.


static void usingforeachloop()
{
string[] carTypes = { "Honda", "BMW", "Ford", "Mercedez" };
foreach (string a in carTypes)
Console.WriteLine(a);


int[] myIntegers = { 10, 20, 30, 40 };
foreach (int i in myIntegers)
Console.WriteLine(i);
}

While and do/While

While looping construct is useful should you wish to execute a block of statements until termination condition has been reached.


static void Whileloop()
{
string userIsFinished = "";
while (userIsFinished.ToLower() != "yes")
{
Console.Write("Are you finished? [Yes] [no]: ");
userIsFinished = Console.ReadLine();
Console.WriteLine("In while loop");
}

Now the difference between while, and do/while loop is that, do/while loop are guarteen to execute atleast one, and incontrast while loop may not execute if the termination condition is false.

do/while loop


static void doWhileloop()
{
string userIsFinished = "";
do
{
Console.WriteLine("In do/while loop");
Console.WriteLine("Are you done? [yes] [No]: ");
userIsFinished = Console.ReadLine();
}
while
(userIsFinished.ToLower() != "yes");
}

Friday, June 6, 2008

Programming Languages

Search Engine Optimization - AddMe

AddThis Feed Button

Submit Your Site To The Web's Top 50 Search Engines for Free!


Technology Blogs - BlogCatalog Blog Directory

My Zimbio
KudoSurf Me!


Hello guys,

Before we jump into C# programming, I wanted to layout a little future plan. At the moment
I am trying to setup information for a full blown website which should be ready early to mid next year. One of my colleague is working with me on this, so it will truly be your Programming One Stop Shop.

Originally my intentions was just to create a C# Winform, and ASP.NET knowledge base site. Well, after giving it some thought, the idea I came up with is to include additional Microsoft languages.

So for the upcoming site, I will include not only C# WinForm, ASP.NET articles and videos, but we will also focus on "C++", "F#", "IronRuby", "IronPython". Now, the goal is to help our .NET Communities, but why not dive into whatever else is out there. From the beginning of my career, I never liked the idea of being narrow minded, so I took my time, got into .NET Programming, and obviously we all are trying to learn new things, and improve our existing knowledge. So, just learning few other languages shouldn't hurt, you just never know when those extras will come in handy. So, once again, our primary focus will be .NET, but from time to time, I will always include whatever else I get my hands on.
By KamranCsharp

Wednesday, June 4, 2008

Chapter 3: C# programming basics

Search Engine Optimization - AddMe

Technology Blogs - BlogCatalog Blog Directory

AddThis Feed Button

Submit Your Site To The Web's Top 50 Search Engines for Free!


My Zimbio
KudoSurf Me!

Now, before we go further, you guys really have to read this. Lot of people think that if you know the syntax then you can program. Well guess what, whenever you hear that, just ignore it. Obviously, whoever said that to you must be really confused.

Syntax is a vital part of programming, but that's not it. When Microsoft introduced .NET, they promised that this platform, framework will be Object Oriented from ground up. Well, that is true. If you can grasp the concept of OOP then you will really pick up fast, and will love programming with passion. Once your OOP concept is clear, then in no time, you will be able to do programming in VB6, C++, C#, VB.NET e.t.c.

So, this is the most important article which you really need to understand.

Pure approach to object oriented programming:

Everything is an object. Now, I want you to think of an object as a fancy variable, which stores data, and you can also "make requests" to that object. You can ask it to perform operations on itself. A program is a bunch of objects telling each other what to do by sending messages to make a request of an object, you "Send a message" to that object. Now when I say message, think of it like a request to call a function that belongs to a particular object.

Every object has a type, each object is an instance of a class, in which "class" is synonymous with "type".All objects of a particular can receive the same message. An object of type "Circle" is also an object of type "shape", a circle will always accept shape messages. So, you can write code that will talk to shapes and automatically handle anything that fits the description of shape. This is one of the the most powerful concepts in OOP.

Now, before you guys go further it would be for your own benefit to read up on objects, more in detail then what I just explained. Next posting is where all the fun begins, YES we will now get into programming.
By KamranCsharp

Thursday, May 29, 2008

Chapter 2: ASP.NET Basics

META TAG Generator

Submit Your Site To The Web's Top 50 Search Engines for Free!


Technology Blogs - BlogCatalog Blog Directory

AddThis Feed Button

My Zimbio
KudoSurf Me!

ASP.NET Basics

ASP.NET pages are text files, and they have .aspx file name extension. They can Be placed on any web server equipped with ASP.NET. So now, when a client requests an ASP.NET page, what happens? Well, the web server passes the page to ASP.NET Runtime, a program that runs on the web server that is responsible for reading the page and compiling it into a .NET class. The class is then used to produce HTML that’s sent back to the user. It’s necessary to understand the ASP.NET Page Structure. Now, if you are a beginner developer, then I would highly recommend that you really understand as to what I am about to show you. I know you guys want to start coding, but if you really get this down, and search about these topics then by the time you will be coding, life will be much simple. I promise you.
If you liked this material then you may also want to get a book by
Cristian Darie & Zak Ruvalcaba called "Build your own ASP.NET 2.0 WEB Site". This book
really helped me out.

  • Now let’s follow these steps:

  • Open Visual Studio.net, click on Create Project

  • Select C#, then select Web, when message opens, select ASP.NET Web Application.

  • Then click ok.

Now, let’s take a look at the Source.

Now these are just very basic which you need to know again before you even think about coding. Also post your comments, and ask questions if you need to know more in depth regarding what Directives exactly are, or Code render blocks e.t.c.
By KamranCsharp

Wednesday, May 28, 2008

1. Intro to ASP.NET and .Net Platform

META TAG Generator

Technology Blogs - BlogCatalog Blog Directory

Search Engine Optimization - AddMe

Submit Your Site To The Web's Top 50 Search Engines for Free!


AddThis Feed Button

My Zimbio
KudoSurf Me!




Chapter 1
Intro to ASP.NET and .NET Platform

Microsoft .NET Framework is a new computing platform for developing
distributed applications. It's an object-oriented framework for defining application, and
one of the most exciting web development technologies on the market today.
ASP.NET is a server side technology for developing web applications based on the
Microsoft .NET Framework.

Early in 2002 Microsoft released new technology for Internet development called ASP.NET.
ASP.NET is a new version of Classic ASP(Active Server Page). It continues to offer flexiblity in terms of language support, range of simple scripting languages, several fully-fledged programming languages. Development in ASP.NET required not only an understanding of HTML and web design, but also a firm grasp of the concepts of object oriented programming and development. When you learn programming in the .NET Framework, you can use your skills in developing different types of applications such as desktop applications, Web applications, and Web services.

.NET Framework is desinged to be object-oriented from the ground up. Before we go further
with web applications, you should know just a few terms such as Class, Inheritance, Namespace, and so on. This will be important right from the beginning.

Classes

A Class is a reference type that encapsulates data (such as constants and fields) and defines its behavior using programming constructs such as methods, properties, contrctors, and events.

Some beginners don't care about understanding it clearly so I think they will have a hard time learning C#.

A CLASS is nothing more than a blueprint of on object. And an object is nothing more than a
"virtual" representation of a CLASS. And when we say Instantiate and object or class, we mean to create the object in memory.

Lets look at a real world example. ( This is also the very first example I learned. )

The class will be a Book
Like anty blueprint, it will contain the attributs of the object it describes. So every book has a name or title, an author, and number of pages.
Class Book
Title
Author
Pages

If I were to instantiate a book( create one ) that class definination ( or blueprint for the object)
requires you to provide the Title, Author and Pages, for that book object.

class Book
{
string m_Title;
string m_Author;
string m_Pages;
}

Inheritance
Inheritance simply means, reusing the interface of the base class. It allows you to create new types based on types that already exist. The original type is called base class, and the inherited class is called a derived class.

Now, this example which I am about to show was taken from codeproject.com, but I have
tried to simplify even more.

When you derive a class from a base class, the derived class will inherit all members of the base class except constructors, though whether the derived class would be able to access those members would depend upon the accessibility of those members in the base class. C# gives us polymorphism through inheritance. Inheritance-based polymorphism allows us to define methods in a base class and override them with derived class implementations. Thus if you have a base class object that might be holding one of several derived class objects, polymorphism when properly used allows you to call a method that will work differently according to the type of derived class the object belongs to.

Now lets take a look at the following class, this will be our base class.
Guys, reading this will not do any good, untill you dont actually do the examples.

1. Open Visual Studio 2005.
2. Click on Create Project.
3. Click on Visual C#, then click on "Console Application".
4. After the console application open, right click on the bold letters "ConsoleApplication"
5. From the menu after you right click it, select "Add". Then from drop down list, select class.
6. Then change the name from Class.cs, to Car.cs.

Car.cs will be our base class, here we go now.

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Car
{
public Car()
{
Console.WriteLine("Car constructor");
}
public void Feature()
{
Console.WriteLine("Car has sports tires");
}
public void Speed()
{
Console.WriteLine("Car is Fast");
}
public virtual void Door()
{
Console.WriteLine("Car has 2 doors");
}
}

Now lets see how we can derive another class from this base class.

1. Now let save this, and lets click on your "Program.cs".


using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Honda : Car
{
public Honda()
{
Console.WriteLine("Honda constructor");
}
public new void Feature()
{
Console.WriteLine("Honda has sports tires");
}
public override void Door()
{
Console.WriteLine("Honda has 2 doors");
}

On the bottom, try this code.


static void Main(string[] args)
{
Car c1 = new Car();
c1.Feature();
c1.Speed();
c1.Door();

// Output
Car constructor
Car has sports tires
Car is Fast
Car has 2 doors
}
}
}

Now, let try this code.


static void Main(string[] args)
{
Car c2 = new Honda();
c2.Feature();
c2.Speed();
c2.Door();

// Output

Car constructor
Honda constructor
Car has sports tires
Car is Fast
Honda has 2 doors
}
}
}

We have an object type Car, but we are now references an object of type Honda. Base class
constructor getting called first followed by the derived class contructor.
Now when we call Door(), we find that the derived class method has got called. This is because in the base class the method is prototyped as public virtual void Door() and in the derived class we have overridden it by using public override void Sing().

So, now you guys have just a little idea as far as what Inheritance is.

Namespace:

As ASP.NET is part of the .NET Framework, we have access to all the goodies that are built into
the form of the .NET Framework Class Library. So, when we have to use a feature that .NET
provides, we only have to find a namespace into our ASP.NET page. Once we have done that, we can make use of the .NET classes in that namespace to achieve our own ends.

For example, if we wanted to access a database from a page, we would import the name that contains classes for the purpose, so in this case I would use " System.Data.SqlClient ".

Guys after you do the examples provided, and read up on this article, you would want to practice a little more before you move on to Chapter 2. Obviously, you are not an expert at this point, but a little patience will come with a greater reward.


By KamranCsharp

ASP.NET Chapters

META TAG Generator

Technology Blogs - BlogCatalog Blog Directory

Search Engine Optimization - AddMe

Submit Your Site To The Web's Top 50 Search Engines for Free!


AddThis Feed Button

My Zimbio
KudoSurf Me!

Hello Everyone,

Here is the basic layout I will use to simplify things.

1. Intro to asp.net and .net platform
2. Asp.net basics
3. C# programming basics
4. Controls
5. Error Handling
6. Logging in
7. Security and user authentication
8. SQL Basics
9. ADO.NET Basics
10. Creating Components and Assemblies
11. Web Services
12. Globalization
13. Deploying a Web Application

I will try for now just to keep things really simple. This way it will be easy to move
from beginning level to advance.

By KamranCsharp

Technology News