Home arrow C# arrow Introduction to Objects and Classes in C#, Part 2
C#

Introduction to Objects and Classes in C#, Part 2


After I wrote the article named Introduction to Objects and Classes in C#, I got a lot of e-mail messages asking me to create a series of articles about Objects and Classes. Actually this was a few months back (sorry for being late), but I'm here again with part two. In Part one, I explained the concepts behinds Objects and Classes but I didn't discuss why Object Oriented Programming (OOP) uses the Object and Class technique. Today, I will discuss the advantage of Objects and Classes with more details on how to understand your problems and develop your Objects for your solution.

Author Info:
By: Michael Youssef
Rating: 4 stars4 stars4 stars4 stars4 stars / 342
May 05, 2004
TABLE OF CONTENTS:
  1. · Introduction to Objects and Classes in C#, Part 2
  2. · Comments
  3. · What's a Scope?
  4. · Private Members Only?

print this article
SEARCH DEVARTICLES

Introduction to Objects and Classes in C#, Part 2
(Page 1 of 4 )

Because this series targets the true beginners, I will not use any technical expressions and I will prefer to explain concepts by examples. I presume that readers have a basic knowledge of C# (control the flow of the program, using methods and arrays, namespaces & assemblies).

The first thing that you should know about C# programming is that it uses the Class to include the data (in part one, I said that data can be stored in instance variables in the class) and methods to process that data. Think about it in the next example:

class Test
{
    
public int Add(int xint y)
    
{
        
return y;
    
}
}

 

The class Test contains a method called Add (which add to integers and return the result) is a good example for what we are talking about. I said that the Class includes data and there are methods to process that data, here the class test includes the method Add() which takes two integer numbers to add them and this is the functionality of the method. The application that will use the Test class can be something like the following:


public class Class1
{
    
public Class1()
    
{
        Test t1 
= new Test();
        Console
.WriteLine(t1.Add(5,4));
    
}
}

 

The concept of Objects & Classes helps you hide your code implementation from the user of your class. In other words, if you develop a class for your friend to use, he doesn't have to know how you created the methods of that class in order to use it; he'll just need to know how to use it, and what functionality is offered by your class members. The point here is that you don't have to know how another developer developed a certain class; you just have to know how to interface with it. And I said in the first part, when you develop programs with C# you will develop classes. Note that this is not like C programming, where the programming primary building block was the function (or methods, in C#). Finally, remember that C# defines other types like structures, enumerations. We'll learn about these in future articles.

In C programming language, programmers develop functions to form their applications. These functions contain the code of the program. The problem is that in large programs, if you have to modify just one line of code you may have to modify many functions to fit in the new modifications. (In procedural languages, functions depend on each other.) But in C#, we write classes as our primary building blocks, and because classes hide their code implementation -- and only the methods of these classes are accessible to the applications that use them -- if we must change something inside the class, we will do it without changing the code of the applications that uses our classes.


blog comments powered by Disqus
C# ARTICLES

- Introduction to Objects and Classes in C#, P...
- Visual C#.NET, Part 1: Introduction to Progr...
- C# - An Introduction
- Hotmail Exposed: Access Hotmail using C#
- Razor Sharp C#
- Introduction to Objects and Classes in C#
- Making Your Code CLS Compliant
- Programming with MySQL and .NET Technologies
- Socket Programming in C# - Part II
- Socket Programming in C# - Part I
- Creational Patterns in C#
- Type Conversions
- Creating Custom Delegates and Events in C#
- Inheritance and Polymorphism
- Understanding Properties in C#

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials