Chat Box

Thursday, June 11, 2009

Zend Studio Enterprise 5.5.1.282

Zend Studio Enterprise 5.5.1.282 | 72.94 MB

The World's most powerful PHP IDE

Proven Zend Studio technology powered by Eclipse
Zend Studio for Eclipse combines proven Zend technology and the Eclipse PHP Developers Tools (PDT) project to create the world̢۪s most powerful IDE for developing rich Web applications. By combining proven Zend PHP editor technology, integration with Zend Platform and Zend Core, built in database connectivity, integrated debugging , profiling, code coverage and testing capabilities, team support with extensible version control support, support for Zend Framework, support for Web Services, comprehensive with multi-language support and extensibility provided by the vibrant Eclipse open source community, developers have the tools they need for support of the entire PHP application lifecycle.

Download:


Wednesday, June 10, 2009

PHP - Ebooks

following are some ebooks on php. more will be provided later...

Book -1

Wamp 2.0 : Apache, MySQL, PHP on Windows

WampServer is a Windows web development environment. It allows you to create web applications with Apache, PHP and the MySQL database. It also comes with PHPMyAdmin and SQLiteManager to easily manage your databases.

WampServer installs automatically (installer), and its usage is very intuitive. You will be able to tune your server without even touching the setting files.

WampServer is the only packaged solution that will allow you to reproduce your production server. Once WampServer is installed, you have the possibility to add as many Apache, MySQL and PHP releases as you want.

WampServer also has a trayicon to manage your server and its settings.
image menu WampServer

Installing


Double click on the downloaded file and just follow the instructions. Everything is automatic. The WampServer package is delivered whith the latest releases of Apache, MySQL and PHP.

Once WampServer is installed, you can add other releases by downloading them on this website. They will then appear in the WampServer menu and you will be able to switch releases with a simple click.
Each release of Apache, MySQL and PHP has its own settings and its own files (datas for MySQL).


Functionalities


WampServer's functionalities are very complete and easy to use so we won't explain here how to use them.

With a left click on WampServer's icon, you will be able to:
- manage your Apache and MySQL services
- switch online/offline (give access to everyone or only localhost)
- install and switch Apache, MySQL and PHP releases
- manage your servers settings
- access your logs
- access your settings files
- create alias

With a right click :
- change WampServer's menu language
- access this page


How to start


When you install WampServer, a "www" directory is created (generally c:\wamp\www). Create a directory inside for your project and put your PHP files in it.
Click on the link "Localhost" in the WampServer menu or open your browser and open the http://localhost address.




Add Apache, MySQL and PHP releases


WampServer allows you to install almost all the existing releases of Apache, PHP and MySQL so you can reproduce exactly the settings of your production server.
To add a new release, donwload it here and install it.

Then click on the WampServer menu and activate the release that you want to use.



Wait until the WampServer icon become white again and start to work.


Downloads


WampServer is an open source project, free to use (GPL licence). If you think our work deserves it and you want to help us, you can make a donation with paypal.



WARNING : do not try to install WampServer 2 over WAMP5.
If WAMP5 is installed on your computer, save your data, uninstall it and delete the WAMP5 directory before installing WampServer 2.


Apache 2.2.11
PHP 5.2.9-2 + PECL
SQLitemanager
MySQL 5.1.33
Phpmyadmin
size: 16Mb



Thursday, April 23, 2009

To generate Megaupload [MU] premium links (for Firefox)

To generate Megaupload [MU] premium links (for Firefox)
found this on this site:
Code:
https://addons.mozilla.org/en-US/firefox/addon/11051
you might want to install this add-on (no waiting time & auto-download) for making it easier too:
Code:
http://www.warez-bb.org/viewtopic.php?t=2281301


TO GENERATE MEGAUPLOAD.COM PREMIUM LINKS:
- install Flashget 1.73
Code:
http://www.brothersoft.com/flashget-74217.html
- install Flashgot Firefox Plugin
Code:
https://addons.mozilla.org/en-US/firefox/addon/220
- turn off and on Mozilla Firefox (to finish install Flashgot and connect with Flashget)
- make Flashget configuration: Tools --> Options -->Connection --> Max simultaneous jobs = 1
(1) open in FF browser Megaupload link
- write captha and press ENTER
- download with Flashgot
- choose SAVE TO location
- be sure, have u got enough HDD space
- press OK to download
- wait until program will reserve place on HDD
- PAUSE LINK after download 50KB
- GENERATE NEXT LINKS --> REPEAT (1)

After generate all links run all jobs (select all links and click green play button)


PS: i think it does the same as Jdownloader, just search for it in google

Sunday, March 15, 2009

STDU Viewer Ver 1.5

STDU Viewer box
Are you tired from many viewers one for each document?
Do you want to have, one program for all your technical documentations, scientific books and so on?
Do you want to have program, which fast opens files, fast loads pages and fast renders page to screen?
And all of this in free software?


markView all most popular documents formats by one program.

STDU Viewer is a document viewer for multiple file formats. The goal of this software is to replace the multiple document viewers with a single simple application. STDU Viewer supports TXT, TIFF, PDF and DjVu documents format. This is most popular formats for scientific and technical documentation.

markUse content for quick jumping from one section to another.

STDU Viewer gives the possibility to show the content of documents for quick jumping from one section to another.

markCreate your own bookmarks for quick access to part of documents

You can create your own named bookmarks for easy access to part of document.

markSTDU Viewer free for non-commercial uses.

Yes. You can use this program without any fees.



Download STDU Viewer (1.5 MB)

Saturday, March 7, 2009

Logic Works 5



Download Link:
http://ifile.it/0v3z8us

Saturday, February 21, 2009

MASM Syntax Highlighting In Visual Studio

MASM syntax highlighting in Visual Studio

When a text editor uses syntax highlighting, language keywords, strings, and other elements appear in different colors. Visual Studio and Visual C++ Express can highlight MASM reserved words and strings, as shown in the following example:

This won't happen automatically, but you can create a syntax definition file named Usertype.dat that contains MASM keywords. Then when Visual Studio (or Visual C++ Express) starts, it reads the syntax file and highlights MASM keywords.

Here are the required steps to set up MASM syntax highlighting in Visual Studio or Visual C++ Express:

1) Download the Usertype.dat file given here to a folder in which you have read/write permissions. If you are using Windows Vista, download to My Documents, or C:\temp, or any folder that doesn't have security restrictions.

2) Copy Usertype.dat to the C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE folder. If you are using Windows Vista, it will display a verification window before copying the file.

3) Open Visual Studio or Visual C++ Express, select Options from the Tools menu, select Text Editor, and select File Extension. On the right side of the dialog (shown below), enter asm as the extension, select Microsoft Visual C++ from the Editor list, and click the Add button. Click the OK button to save your changes.

Close Visual Studio and restart it. Open your project and display an ASM file. You should see syntax highlighting in the editor.

How To Use Visual Studio For Running Assembly Code

You might be interested to know more about how Visual C++ projects are set up for assembly language programs. Follow the following steps to use .Net Framework to assemble your assembly code. First of all install VS 2005 or VS 2008 complete and extract the content of irvine.exe
Download Irvine.exe for VS 2005
Download Irvine.exe for VS 2008

Now open Visual Studio and choose File -> New -> Project .

Select Visual C++ in left column and Empty Project in Right Column. Give a name to your project i.e. "Project 1" and click OK.


Right Click on the project in Solution Explorer and Choose "Custom Build Rules". or open it from Project menu i.e . Project -> Custom Build Rules


Int that Dialog Box mark "Microsoft Macro Assembler" as checked. and click OK


Now open Add New Item dialog box by right clicking in the solution explorer and choosing Add -> New Item.. Or you can also open Add New Item dialog box from toolbar button.

In Add New Item dialog box choose Code from left column and C++ File(.cpp) from right column. and give it any name with .asm extension. Like i have given it a name main.asm. Remember .asm extension is necessary.


Now select Project Properties from the Project menu. Expand the entry under Configuration Properties. Then expand the entry named Microsoft Macro Assembler. This is what you should see:

Click the entry named General under Microsoft Macro Assembler . Notice that the Include Paths option has been set to the c:\Irvine directory. This tells the assembler where to find files having a filename extension of ".inc". Here is a sample:

Find the Linker entry under Configuration Properties. Select the Input entry, and notice that two filenames have been added to the Additional Dependencies entry. The user32.lib file is a standard MS-Windows file. The irvine32.lib file is the link library file supplied with this book. There must be at least one space separating the file names:

Next, select Linker under Configuration Properties, and then select General. The Additional Library Directories option equals c:\Irvine, so the linker can find the Irvine32.lib library file:

Select Linker under the Configuration Properties and select Debugging. Notice that the Generate Debug Info option is set to Yes:

Select System under the Linker entry. Notice that the SubSystem option has been set to Console:

We use the Console setting because it is easy for assembly language programs to write output to a text console (Command) window. This is the window you see when running cmd.exe from the Start > Run menu in Windows.

Click the OK button to close the Project Property Pages window.


Now you have set up correctly so do start coding but remember to write the first line of code as

INCLUDE irvine32.inc

AVS Video Tools 5.1




Online Media Technologies Ltd., presents AVS Video Tools 5.1, the brand new version of its top-market complete solution for home video production. Now ultimate all-in-one suite of six fully featured, wizard-driven applications for capturing, multi-format cross converting, video editing, mobile content management, home video DVD burning and ripping handles all key user requirements for home video processing. AVS Video Tools 5.1 keeps all the advantages of its predecessor, AVS Video Converter and adds new tools and features for more enhanced yet maximum simplified work with your video and audio.

AVS Video Tools 5.1 is the update to AVS Video Converter 4.3, the company’s time-proved product, highly popular among todays international users. With time we beefed up AVS Video Converter with some major innovations making it useful for a wide range of tasks such as all key file formats converting, transferring DVDs and video files to Apple iPod, Sony PSP, media portable players and mobiles, fast and direct ads removal from MPEGs without re-encoding and many others. As a result, the software turned into the complete tool for home video handling that encouraged us to give the software a more appropriate name AVS Video Tools 5.1.

The new version offers a new added tool - AVS Video Cutter, the video processing application intended for fast removing the unwanted parts or commercials from your videos recorded with various PVR or DVD camcorders. Specifically designed algorithm ensures the automatic, exact and time-saving scene detection by scanning and splitting your video into episodes. And on top of that, AVS Video Cutter allows you to directly save your already edited videos without their re-conversion, which eliminates the problem of quality loss.

Based on our users feedback we made some corrections for more powerful and efficient work with the creation of DVD videos. Now due to the supported customizable aspect ratio feature you can select, adjust or just learn the aspect ratio of your video. As a result, the update provides you with more flexibility in controlling your video processing. Choose 16:9 (widescreen format) or 4:3 (fullscreen format) aspect ratio according to your liking and enjoy every minute of movie watching.

AVS Video Tools 5.1 features a wider set of capturing options. Now it supports MPEG2 capturing encoding that means that owners of MPEG2 TV-Tuners or funs of satellite TV can easily and trouble-free capture most favorite movies or memorable moments of popular programs.

http://rapidshare.com/files/61552314/AVS51.part1.rar

http://rapidshare.com/files/61553177/AVS51.part2.rar

http://rapidshare.com/files/61554128/AVS51.part3.rar

http://rapidshare.com/files/61555029/AVS51.part4.rar

http://rapidshare.com/files/61555445/AVS51.part5.rar

Password: hoaxfree.com

Friday, February 20, 2009

C#.Net Interview Question

1.What’s the implicit name of the parameter that gets passed into the class’ set method?
Value, and its datatype depends on whatever variable we’re changing.

2.How do you inherit from a class in C#?
Place a colon and then the name of the base class. Notice that it’s double colon in C++.

3.Does C# support multiple inheritance? No, use interfaces instead.

4.When you inherit a protected class-level variable, who is it available to?
Classes in the same namespace.

5.Are private class-level variables inherited? Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are.

6.Describe the accessibility modifier protected internal?
It’s available to derived classes and classes within the same Assembly (and naturally from the base class it’s declared in).

7.C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write?
Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there’s no implementation in it.

8.What’s the top .NET class that everything is derived from?
System.Object.

9.How’s method overriding different from overloading? When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class.

10.What does the keyword virtual mean in the method definition? The method can be over-ridden.

11.Can you declare the override method static while the original method is non-static?
No, you can’t, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override.

12.Can you override private virtual methods? No, moreover, you cannot access private methods in inherited classes, have to be protected in the base class to allow any sort of access.

13.Can you prevent your class from being inherited and becoming a base class for some other classes?
Yes, that’s what keyword sealed in the class definition is for. The developer trying to derive from your class will get a message: cannot inherit from Sealed class WhateverBaseClassName. It’s the same concept as final class in Java.

14.Can you allow class to be inherited, but prevent the method from being over-ridden?
Yes, just leave the class public and make the method sealed.

15.What’s an abstract class?
A class that cannot be instantiated. A concept in C++ known as pure virtual method. A class that must be inherited and have the methods over-ridden. Essentially, it’s a blueprint for a class without any implementation.

16.When do you absolutely have to declare a class as abstract (as opposed to free-willed educated choice or decision based on UML diagram)?
When at least one of the methods in the class is abstract. When the class itself is inherited from an abstract class, but not all base abstract methods have been over-ridden.

17.What’s an interface class?
It’s an abstract class with public abstract methods all of which must be implemented in the inherited classes.

18.Why can’t you specify the accessibility modifier for methods inside the interface?
They all must be public. Therefore, to prevent you from getting the false impression that you have any freedom of choice, you are not allowed to specify any accessibility, it’s public by default.

19.Can you inherit multiple interfaces?
Yes, why not.

20.And if they have conflicting method names? It’s up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you’re okay.

21.What’s the difference between an interface and abstract class?
In the interface all methods must be abstract; in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.

22.How can you overload a method?
Different parameter data types, different number of parameters, different order of parameters.

23.If a base class has a bunch of overloaded constructors, and an inherited class has another bunch of overloaded constructors, can you enforce a call from an inherited constructor to an arbitrary base constructor?
Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.

24.What’s the difference between System.String and System.StringBuilder classes? System.String is immutable; System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

25.What’s the advantage of using System.Text.StringBuilder over System.String? StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it’s being operated on, a new instance is created.

26.Can you store multiple data types in System.Array?
No.

27.What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
The first one performs a deep copy of the array, the second one is shallow.

28.How can you sort the elements of the array in descending order?
By calling Sort() and then Reverse() methods.

29.What’s the .NET datatype that allows the retrieval of data by a unique key? HashTable.

30.What’s class SortedList underneath?
A sorted HashTable.


31.Will finally block get executed if the exception had not occurred?

Yes.

32.What’s the C# equivalent of C++ catch (…), which was a catch-all statement for any possible exception?
A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.

33.Can multiple catch blocks be executed?
No, once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block.

34.Why is it a bad idea to throw your own exceptions?
Well, if at that point you know that an error has occurred, then why not write the proper code to handle that error instead of passing a new Exception object to the catch block? Throwing your own exceptions signifies some design flaws in the project.

35.What’s a delegate?
A delegate object encapsulates a reference to a method. In C++ they were referred to as function pointers.

36.What’s a multicast delegate?
It’s a delegate that points to and eventually fires off several methods.

37.How’s the DLL Hell problem solved in .NET?
Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly.

38.What are the ways to deploy an assembly?
An MSI installer, a CAB archive, and XCOPY command.

39.What’s a satellite assembly?
When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.

40.What namespaces are necessary to create a localized application? System.Globalization, System.Resources.

41.What’s the difference between // comments, /* */ comments and /// comments?
Single-line, multi-line and XML documentation comments.

42.How do you generate documentation from the C# file commented properly with a command-line compiler?
Compile it with a /doc switch.

43.What’s the difference between c and code XML documentation tag?
Single line code example and multiple-line code example.

44.Is XML case-sensitive?
Yes, so Student and student are different elements.

45.What debugging tools come with the .NET SDK?
CorDBG – command-line debugger, and DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR. To use CorDbg, you must compile the original C# file using the /debug switch.
46.What does the This window show in the debugger?
It points to the object that’s pointed to by this reference. Object’s instance data is shown.

47.What does assert() do?
In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.

48.What’s the difference between the Debug class and Trace class?
Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.

49.Why are there five tracing levels in System.Diagnostics.TraceSwitcher?
The tracing dumps can be quite verbose and for some applications that are constantly running you run the risk of overloading the machine and the hard drive there. Five levels range from None to Verbose, allowing to fine-tune the tracing activities.

50.Where is the output of TextWriterTraceListener redirected?
To the Console or a text file depending on the parameter passed to the constructor.

51.How do you debug an ASP.NET Web application?
Attach the aspnet_wp.exe process to the DbgClr debugger.

52.What are three test cases you should go through in unit testing?
Positive test cases (correct data, correct output), negative test cases (broken or missing data, proper handling), exception test cases (exceptions are thrown and caught properly).

53.Can you change the value of a variable while debugging a C# application?
Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.

54.Explain the three services model (three-tier application)?
Presentation (UI), business (logic and underlying code) and data (from storage or other sources).

55.What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?
SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix, but it’s a .NET layer on top of OLE layer, so not the fastest thing in the world. ODBC.NET is a deprecated layer provided for backward compatibility to ODBC engines.

56.What’s the role of the DataReader class in ADO.NET connections?
It returns a read-only dataset from the data source when the command is executed.

57.What is the wildcard character in SQL?
Let’s say you want to query database with LIKE for all employees whose name starts with La. The wildcard character is %, the proper query with LIKE would involve ‘La%’.

58.Explain ACID rule of thumb for transactions?
Transaction must be Atomic (it is one unit of work and does not dependent on previous and following transactions), Consistent (data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t), Isolated (no transaction sees the intermediate results of the current transaction), Durable (the values persist if the data had been committed even if the system crashes right after).

59.What connections does Microsoft SQL Server support?
Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and passwords).

60.Which one is trusted and which one is untrusted?
Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction.

61.Why would you use untrusted verificaion?
Web Services might use it, as well as non-Windows applications.

62.What does the parameter Initial Catalog define inside Connection String?
The database name to connect to.

63.What’s the data provider name to connect to Access database?
Microsoft.Access.

64.What does Dispose method do with the connection object?
Deletes it from the memory.

65.What is a pre-requisite for connection pooling?
Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings.

C#.Net Interview Question

1.What’s the implicit name of the parameter that gets passed into the class’ set method?
Value, and its datatype depends on whatever variable we’re changing.

2.How do you inherit from a class in C#?
Place a colon and then the name of the base class. Notice that it’s double colon in C++.

3.Does C# support multiple inheritance? No, use interfaces instead.

4.When you inherit a protected class-level variable, who is it available to?
Classes in the same namespace.

5.Are private class-level variables inherited? Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are.

6.Describe the accessibility modifier protected internal?
It’s available to derived classes and classes within the same Assembly (and naturally from the base class it’s declared in).

7.C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write?
Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there’s no implementation in it.

8.What’s the top .NET class that everything is derived from?
System.Object.

9.How’s method overriding different from overloading? When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class.

10.What does the keyword virtual mean in the method definition? The method can be over-ridden.

11.Can you declare the override method static while the original method is non-static?
No, you can’t, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override.

12.Can you override private virtual methods? No, moreover, you cannot access private methods in inherited classes, have to be protected in the base class to allow any sort of access.

13.Can you prevent your class from being inherited and becoming a base class for some other classes?
Yes, that’s what keyword sealed in the class definition is for. The developer trying to derive from your class will get a message: cannot inherit from Sealed class WhateverBaseClassName. It’s the same concept as final class in Java.

14.Can you allow class to be inherited, but prevent the method from being over-ridden?
Yes, just leave the class public and make the method sealed.

15.What’s an abstract class?
A class that cannot be instantiated. A concept in C++ known as pure virtual method. A class that must be inherited and have the methods over-ridden. Essentially, it’s a blueprint for a class without any implementation.

16.When do you absolutely have to declare a class as abstract (as opposed to free-willed educated choice or decision based on UML diagram)?
When at least one of the methods in the class is abstract. When the class itself is inherited from an abstract class, but not all base abstract methods have been over-ridden.

17.What’s an interface class?
It’s an abstract class with public abstract methods all of which must be implemented in the inherited classes.

18.Why can’t you specify the accessibility modifier for methods inside the interface?
They all must be public. Therefore, to prevent you from getting the false impression that you have any freedom of choice, you are not allowed to specify any accessibility, it’s public by default.

19.Can you inherit multiple interfaces?
Yes, why not.

20.And if they have conflicting method names? It’s up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you’re okay.

21.What’s the difference between an interface and abstract class?
In the interface all methods must be abstract; in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.

22.How can you overload a method?
Different parameter data types, different number of parameters, different order of parameters.

23.If a base class has a bunch of overloaded constructors, and an inherited class has another bunch of overloaded constructors, can you enforce a call from an inherited constructor to an arbitrary base constructor?
Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.

24.What’s the difference between System.String and System.StringBuilder classes? System.String is immutable; System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

25.What’s the advantage of using System.Text.StringBuilder over System.String? StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it’s being operated on, a new instance is created.

26.Can you store multiple data types in System.Array?
No.

27.What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
The first one performs a deep copy of the array, the second one is shallow.

28.How can you sort the elements of the array in descending order?
By calling Sort() and then Reverse() methods.

29.What’s the .NET datatype that allows the retrieval of data by a unique key? HashTable.

30.What’s class SortedList underneath?
A sorted HashTable.


31.Will finally block get executed if the exception had not occurred?

Yes.

32.What’s the C# equivalent of C++ catch (…), which was a catch-all statement for any possible exception?
A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.

33.Can multiple catch blocks be executed?
No, once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block.

34.Why is it a bad idea to throw your own exceptions?
Well, if at that point you know that an error has occurred, then why not write the proper code to handle that error instead of passing a new Exception object to the catch block? Throwing your own exceptions signifies some design flaws in the project.

35.What’s a delegate?
A delegate object encapsulates a reference to a method. In C++ they were referred to as function pointers.

36.What’s a multicast delegate?
It’s a delegate that points to and eventually fires off several methods.

37.How’s the DLL Hell problem solved in .NET?
Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly.

38.What are the ways to deploy an assembly?
An MSI installer, a CAB archive, and XCOPY command.

39.What’s a satellite assembly?
When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.

40.What namespaces are necessary to create a localized application? System.Globalization, System.Resources.

41.What’s the difference between // comments, /* */ comments and /// comments?
Single-line, multi-line and XML documentation comments.

42.How do you generate documentation from the C# file commented properly with a command-line compiler?
Compile it with a /doc switch.

43.What’s the difference between c and code XML documentation tag?
Single line code example and multiple-line code example.

44.Is XML case-sensitive?
Yes, so Student and student are different elements.

45.What debugging tools come with the .NET SDK?
CorDBG – command-line debugger, and DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR. To use CorDbg, you must compile the original C# file using the /debug switch.
46.What does the This window show in the debugger?
It points to the object that’s pointed to by this reference. Object’s instance data is shown.

47.What does assert() do?
In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.

48.What’s the difference between the Debug class and Trace class?
Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.

49.Why are there five tracing levels in System.Diagnostics.TraceSwitcher?
The tracing dumps can be quite verbose and for some applications that are constantly running you run the risk of overloading the machine and the hard drive there. Five levels range from None to Verbose, allowing to fine-tune the tracing activities.

50.Where is the output of TextWriterTraceListener redirected?
To the Console or a text file depending on the parameter passed to the constructor.

51.How do you debug an ASP.NET Web application?
Attach the aspnet_wp.exe process to the DbgClr debugger.

52.What are three test cases you should go through in unit testing?
Positive test cases (correct data, correct output), negative test cases (broken or missing data, proper handling), exception test cases (exceptions are thrown and caught properly).

53.Can you change the value of a variable while debugging a C# application?
Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.

54.Explain the three services model (three-tier application)?
Presentation (UI), business (logic and underlying code) and data (from storage or other sources).

55.What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?
SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix, but it’s a .NET layer on top of OLE layer, so not the fastest thing in the world. ODBC.NET is a deprecated layer provided for backward compatibility to ODBC engines.

56.What’s the role of the DataReader class in ADO.NET connections?
It returns a read-only dataset from the data source when the command is executed.

57.What is the wildcard character in SQL?
Let’s say you want to query database with LIKE for all employees whose name starts with La. The wildcard character is %, the proper query with LIKE would involve ‘La%’.

58.Explain ACID rule of thumb for transactions?
Transaction must be Atomic (it is one unit of work and does not dependent on previous and following transactions), Consistent (data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t), Isolated (no transaction sees the intermediate results of the current transaction), Durable (the values persist if the data had been committed even if the system crashes right after).

59.What connections does Microsoft SQL Server support?
Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and passwords).

60.Which one is trusted and which one is untrusted?
Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction.

61.Why would you use untrusted verificaion?
Web Services might use it, as well as non-Windows applications.

62.What does the parameter Initial Catalog define inside Connection String?
The database name to connect to.

63.What’s the data provider name to connect to Access database?
Microsoft.Access.

64.What does Dispose method do with the connection object?
Deletes it from the memory.

65.What is a pre-requisite for connection pooling?
Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings.

Monday, February 16, 2009

Free Rapidshare Premium Accounts

BEST WAY TO LEGALLLY OWN A RAPIDSHARE 1 YEAR PREMIUM ACCOUNT.

Follow these steps:

1. Create a PayPal PREMIUM Account from the following link. It is free
Click Here To Create Free PayPal Account

When asked for credit card details simply say cancel. You do not need to fill it. And in address if PayPal is not providing service in your country then choose some fake country. Like Pakistan is not listed in so you can choose UAE, USA or anywhere else.

2. Then go to the following link $6.00 Welcome Survey After Free Registration!

Join this site. It is also free. You get paid for completing surveys over there 6$ to 4$ dollars per survey and 1.25$ per referral thats a lot u will get a premium account of 1 year in weeks time. I myself have a 1 year premium account and now i am collecting some exta cash .

4. Another thing you can also use paypal money to buy stuff on ebay and other shopping sites.

5. Thats is it. So Simple. it really works.

Friday, February 13, 2009

Assembly Tutorials

X86 Assembly

This is an open content wiki book about assembly language programming. The book includes sections on the history of the X86 architecture, the X86 family and programming in X86 assembly.


MIPS Assembly

This is the wikibooks entry for MIPS assembly that discusses the MIPS architecture and MIPS programming.


Programmed Introduction to MIPS Assembly Language

This is a course in assembly language programming of the MIPS processor. It emphasizes the topics needed for study of computer architecture: bits, bit patterns, operations on bit patterns, and how bit patterns represent instructions and data.


Learning Assembly

A beginner-level tutorial that introduces assembly language.


Win32 Assembler Coding Tutorial

This site also has some additional assembler and programming resources that you can access from the drop down menus at the top of the page.


101% Assembler

This site is dedicated to assembly language programming. It features some assembler tool downloads and source code examples.


Programming from the Ground Up (1.4 Mb PDF file)

A book on assembly for the newbie to the pro. It covers how the cpu works as well as writting programs.


Introduction to Assembly Language

This web page examines assembly languages in a general manner. Specific examples of addressing modes and instructions from various processors are used to illustrate the general nature of assembly language.


Assembly Language Tutor

This is an introduction for people who want to program in assembler language.


The Art of Assembly Language Programming

Online book available for Windows, DOS and Linux assembly programming. Teaches High Level Assembly (HLA) - you will need to download the HLA compiler and supporting files.


PC Assembly Tutorial

The tutorial has extensive coverage of interfacing assembly and C code and so might be of interest to C programmers who want to learn about how C works under the hood. All the examples use the free NASM (Netwide) assembler.


Assembly Language Programming

PowerPoint and HTML Presentations on Various Assembly Language Topics.


Assembly Tutorial

This is for all you folks out there, who want to learn the magic art of Assembly programming.


Linux Assembly

If you are looking for information on assembly programming under UNIX-like operating systems, this is the right place to be. Here you can find various resources, ranging from tutorials and documentation, to actual programs written in assembly language.


Linux Assembly "Hello World" Tutorial

Designed to familiarize the reader with programming in x86 assembly under Linux and how to interface assembly and higher-level language code. The tutorial will also briefly cover debugging your assembly using GDB.

Sunday, February 8, 2009

Object Oriented Concepts in C#


In this post the key concepts of object oriented programming are discussed.

Key Concepts of Object Orientation

  • Abstraction
  • Encapsulation
  • Polymorphism
  • Inheritance.

Abstraction is the ability to generalize an object as a data type that has a specific set of characteristics and is able to perform a set of actions.

Object-oriented languages provide abstraction via classes. Classes define the properties and methods of an object type.

Examples:

  • You can create an abstraction of a dog with characteristics, such as color, height, and weight, and actions such as run and bite. The characteristics are called properties, and the actions are called methods.
  • A Recordset object is an abstract representation of a set of data.

Classes are blueprints for Object.
Objects are instance of classes.

C# Example of Class:

public class Draw
{
// Class code.
}

Object References

When we work with an object we are using a reference to that object. On the other hand, when we are working with simple data types such as Integer, we are working with the actual value rather than a reference.

When we create a new object using the New keyword, we store a reference to that object in a variable. For instance:

Draw MyDraw = new Draw;

This code creates a new instance of Draw. We gain access to this new object via the MyDraw variable. This variable holds a reference to the object.

Now we have a second variable, which also has a reference to that same object. We can use either variable interchangeably, since they both reference the exact same object. The thing we need to remember is that the variable we have is not the object itself but, rather, is just a reference or pointer to the object itself.

Early binding means that our code directly interacts with the object, by directly calling its methods. Since the compiler knows the object's data type ahead of time, it can directly compile code to invoke the methods on the object. Early binding also allows the IDE to use IntelliSense to aid our development efforts; it allows the compiler to ensure that we are referencing methods that do exist and that we are providing the proper parameter values.

Late binding means that our code interacts with an object dynamically at run-time. This provides a great deal of flexibility since our code literally doesn't care what type of object it is interacting with as long as the object supports the methods we want to call. Because the type of the object isn't known by the IDE or compiler, neither IntelliSense nor compile-time syntax checking is possible but we get unprecedented flexibility in exchange.

If we enable strict type checking by using Option Strict On at the top of our code modules, then the IDE and compiler will enforce early binding behavior. By default, Option Strict is turned off and so we have easy access to the use of late binding within our code.

Access Modifiers

Access Modifiers are keywords used to specify the declared accessibility of a member of a type.

Public is visible to everyone. A public member can be accessed using an instance of a class, by a class's internal code, and by any descendants of a class.

Private is hidden and usable only by the class itself. No code using a class instance can access a private member directly and neither can a descendant class.



Protected members are similar to private ones in that they are accessible only by the containing class. However, protected members also may be used by a descendant class. So members that are likely to be needed by a descendant class should be marked protected.



Internal/Friend is public to the entire application but private to any outside applications. Internal is useful when you want to allow a class to be used by other applications but reserve special functionality for the application that contains the class. Internal is used by C# and Friend by VB .NET.



Protected Internal may be accessed only by a descendant class that's contained in the same application as its base class. You use protected internal in situations where you want to deny access to parts of a class functionality to any descendant classes found in other applications.

Composition of an OBJECT

We use an interface to get access to an object's data and behavior. The object's data and behaviors are contained within the object, so a client application can treat the object like a black box accessible only through its interface. This is a key object-oriented concept called Encapsulation. The idea is that any programs that make use of this object won't have direct access to the behaviors or data-but rather those programs must make use of our object's interface.

There are three main parts of Object:

1. Interface
2. Implementation or Behavior
3. Member or Instance variables

Interface

The interface is defined as a set of methods (Sub and Function routines), properties (Property routines), events, and fields (variables or attributes) that are declared Public in scope.

Implementation or Behavior

The code inside of a method is called the implementation. Sometimes it is also called behavior since it is this code that actually makes the object do useful work.
Client applications can use our object even if we change the implementation-as long as we don't change the interface. As long as our method name and its parameter list and return data type remain unchanged, we can change the implementation all we want.

So Method Signature depends on:

  • Method name
  • Data types of parameters
  • Either Parameter is passed ByVal or ByRef.
  • Return type of method.

It is important to keep in mind that encapsulation is a syntactic tool-it allows our code to continue to run without change. However, it is not semantic-meaning that, just because our code continues to run, doesn't mean it continues to do what we actually wanted it to do.

Member or Instance Variables

The third key part of an object is its data, or state. Every instance of a class is absolutely identical in terms of its interface and its implementation-the only thing that can vary at all is the data contained within that particular object.

Member variables are those declared so that they are available to all code within our class. Typically member variables are Private in scope-available only to the code in our class itself. They are also sometimes referred to as instance variables or as attributes. The .NET Framework also refers to them as fields.
We shouldn't confuse instance variables with properties. A Property is a type of method that is geared around retrieving and setting values, while an instance variable is a variable within the class that may hold the value exposed by a Property.

Interface looks like a class, but has no implementation.

The only thing it contains is definitions of events, indexers, methods and/or properties. The reason interfaces only provide definitions is because they are inherited by classes and structs, which must provide an implementation for each interface member defined. So, what are interfaces good for if they don't implement functionality? They're great for putting together plug-n-play like architectures where components can be interchanged at will. Since all interchangeable components implement the same interface, they can be used without any extra programming. The interface forces each component to expose specific public members that will be used in a certain way.

Because interfaces must be defined by inheriting classes and structs, they define a contract. For instance, if class foo inherits from the IDisposable interface, it is making a statement that it guarantees it has the Dispose() method, which is the only member of the IDisposable interface. Any code that wishes to use class foo may check to see if class foo inherits IDisposable. When the answer is true, then the code knows that it can call foo.Dispose().

Defining an Interface: MyInterface.c

interface IMyInterface
{
void MethodToImplement();
}

Above listing shows defines an interface named IMyInterface. A common naming convention is to prefix all interface names with a capital "I", but this is not mandatory. This interface has a single method named MethodToImplement(). This could have been any type of method declaration with different parameters and return types. Notice that this method does not have an implementation (instructions between curly braces- {}), but instead ends with a semi-colon, ";". This is because the interface only specifies the signature of methods that an inheriting class or struct must implement.

All the methods of Interface are public by default and no access modifiers (like private, public) are allowed with any method of Interface.

Using an Interface: InterfaceImplementer.cs

class InterfaceImplementer : IMyInterface
{
public void MethodToImplement()
{
Console.WriteLine("MethodToImplement() called.");
}
}

The InterfaceImplementer class in above listing implements the IMyInterface interface. Indicating that a class inherits an interface is the same as inheriting a class. In this case, the following syntax is used:

class InterfaceImplementer : IMyInterface

Note that this class inherits the IMyInterface interface; it must implement its all members. While implementing interface methods all those needs to be declared public only. It does this by implementing the MethodToImplement() method. Notice that this method implementation has the exact same signature, parameters and method name, as defined in the IMyInterface interface. Any difference will cause a compiler error. Interfaces may also inherit other interfaces. Following listing shows how inherited interfaces are implemented.

Interface Inheritance: InterfaceInheritance.cs

using System;
interface IParentInterface
{
void ParentInterfaceMethod();
}
interface IMyInterface : IParentInterface
{
void MethodToImplement();
}
class InterfaceImplementer : IMyInterface
{
public void MethodToImplement()
{
Console.WriteLine("MethodToImplement() called.");
}
public void ParentInterfaceMethod()
{
Console.WriteLine("ParentInterfaceMethod() called.");
}
}

The code in above listing contains two interfaces: IMyInterface and the interface it inherits, IParentInterface. When one interface inherits another, any implementing class or struct must implement every interface member in the entire inheritance chain. Since the InterfaceImplementer class in above listing inherits from IMyInterface, it also inherits IParentInterface. Therefore, the InterfaceImplementer class must implement the MethodToImplement() method specified in the IMyInterface interface and the ParentInterfaceMethod() method specified in the IParentInterface interface.

In summary, you can implement an interface and use it in a class. Interfaces may also be inherited by other interface. Any class or struct that inherits an interface must also implement all members in the entire interface inheritance chain.

Inheritance is the idea that one class, called a subclass, can be based on another class, called a base class. Inheritance provides a mechanism for creating hierarchies of objects.

Inheritance is the ability to apply another class's interface and code to your own class.

Normal base classes may be instantiated themselves, or inherited. Derived classes can inherit base class members marked with protected or greater access. The derived class is specialized to provide more functionality, in addition to what its base class provides. Inheriting base class members in derived class is not mandatory.

Access Keywords

base -> Access the members of the base class.
this -> Refer to the current object for which a method is called.

The base keyword is used to access members of the base class from within a derived class:
Call a method on the base class that has been overridden by another method. Specify which base-class constructor should be called when creating instances of the derived class. A base class access is permitted only in a constructor, an instance method, or an instance property accessor.

In following example, both the base class, Person, and the derived class, Employee, have a method named Getinfo. By using the base keyword, it is possible to call the Getinfo method on the base class, from within the derived class.

// Accessing base class members

using System;
public class Person
{
protected string Cell = "0332-2267283";
protected string name = "M. Jawaid";
public virtual void GetInfo()
{
Console.WriteLine("Name: {0}", name);
Console.WriteLine("CELL: {0}", Cell);
}
}
class Employee: Person
{
public string id = "ABC567EFG";
public override void GetInfo()
{
// Calling the base class GetInfo method:
base.GetInfo();
Console.WriteLine("Employee ID: {0}", id);
}
}
class TestClass
{
public static void Main()
{
Employee E = new Employee();
E.GetInfo();
}
}

Output
Name: M. Jawaid
CELL: 0332-2267283
Employee ID: ABC567EFG

Base class constructors can be called from derived classes. To call a base class constructor, use the base() constructor reference. This is desirable when it's necessary to initialize a base class appropriately.

Here's an example that shows the derived class constructor with an address parameter:

abstract
public class Contact
{
private string address;
public Contact(string b_address)
{
this.address = b_address;
}
}
public class Customer : Contact
{
public Customer(string c_address) : base(C_address)
{
}
}

In this code, the Customer class does not have an address, so it passes the parameter to its base class constructor by adding a colon and the base keyword with the parameter to its declaration. This calls the Contact constructor with the address parameter, where the address field in Contact is initialized.

One more example which shows how base-class constructor is called when creating instances of a derived class:

using System;
public class MyBase
{
int num;
public MyBase()
{
Console.WriteLine("In MyBase()");
}
public MyBase(int i)
{
num = i;
Console.WriteLine("in MyBase(int i)");
}
public int GetNum()
{
return num;
}
}
public class MyDerived : MyBase
{
static int i = 32;
// This constructor will call MyBase.MyBase()
public MyDerived(int ii) : base()
{
}
// This constructor will call MyBase.MyBase(int i)
public MyDerived() : base(i)
{
}
public static void Main()
{
MyDerived md = new MyDerived(); // calls public MyDerived() : base(i) and
// passes i=32 in base class
MyDerived md1 = new MyDerived(1); // call public MyDerived() : base(i)
}
}

Output
in MyBase(int i)
in MyBase()

The following example will not compile. It illustrates the effects of not including a default constructor in a class definition:

abstract
public class Contact
{
private string address;
public Contact(string address)
{
this.address = address;
}
}
public class Customer : Contact
{
public Customer(string address)
{
}
}

In this example, the Customer constructor does not call the base class constructor. This is obviously a bug, since the address field will never be initialized.

When a class has no explicit constructor, the system assigns a default constructor. The default constructor automatically calls a default or parameterless base constructor. Here's an example of automatic default constructor generation that would occur for the preceding example:

public Customer() : Contact()
{
}

When a class does not declare any constructors, the code in this example is automatically generated. The default base class constructor is called implicitly when no derived class constructors are defined. Once a derived class constructor is defined, whether or not it has parameters, a default constructor will not be automatically defined, as the preceding code showed.

Calling Base Class Members

Derived classes can access the members of their base class if those members have protected or greater access. Simply use the member name in the appropriate context, just as if that member were a part of the derived class itself. Here's an example:

abstract public class Contact
{
private string address;
private string city;
private string state;
private string zip;
public string FullAddress()
{
string fullAddress = address + '\n' + city + ',' + state + ' ' + zip;
return fullAddress;
}
}
public class Customer : Contact
{
public string GenerateReport()
{
string fullAddress = FullAddress();
// do some other stuff...
return fullAddress;
}
}

In above example, the GenerateReport() method of the Customer class calls the FullAddress() method in its base class, Contact. All classes have full access to their own members without qualification. Qualification refers to using a class name with the dot operator to access a class member-MyObject.SomeMethod(), for instance. This shows that a derived class can access its base class members in the same manner as its own.

More Tips regarding Inheritance:

  • A static member cannot be marked as override, virtual, or abstract. So following is an error:
    public static virtual void GetCELL()
  • You can't call static methods of base class from derived class using base keyword.
    In above example if you declare a static method as follows:

public class Person
{
protected string Cell = "0332-2267283";
protected string name = "M. Jawaid";
public static void GetInfo()
{
// Implementation
}
}

now you can't call this method using base.GetInfo() from derived class instead you have to call Person.GetInfo() from derived class.

Inside Static members we can access only static fields, methods etc.
Following example will give error, because we can't access name in GetInfo() because name is not static.

public class Person
{
protected string Cell = "0332-2267283";
protected string name = "M. Jawaid";
public static void GetInfo()
{
Console.WriteLine("Name: {0}", name);
Console.WriteLine("CELL: {0}", Cell);
}
}

Virtual or abstract members cannot be private.

  • If you are not overriding a virtual method of base class in derived class, you can't use base class method by using base keyword in derived class. Also when you will create an instance of derived class, it will call derived class method and you will only be able to access base class method when you will create instance of base class.
  • You can't decrease access level of a method in derived class when you are overriding a base class method in derived class, vice versa is possible.
    Means you can make protected method of base class to public in derived class.

The "this" keyword refers to:

  • the current instance for which a method is called. Static member functions do not have a this pointer. The this keyword can be used to access members from within constructors, instance methods, and instance accessors.
    The following are common uses of this:

To qualify members hidden by similar names, for example:

public Employee(string name, string alias)
{
this.name = name;
this.alias = alias;
}

In above example, this.name refers to private variable name in the class. If we write name = name, then this will refer to argument name of the constructor Employee and not to private variable name in the class. In this case private variable name will never be initialized.

  • To pass an object as a parameter to other methods, for example:
    CalcTax(this);

To declare indexers, for example:

public int this [int param]
{
get
{
return array[param];
}
set
{
array[param] = value;
}
}

It is an error to refer to this in a static method, static property accessor, or variable initializer of a field declaration.

In this example, this is used to qualify the Employee class members, name and alias, which are hidden by similar names. It is also used to pass an object to the method CalcTax, which belongs to another class.

// keywords_this.cs
// this example
using System;
public class Employee
{
public string name;
public string alias;
public decimal salary = 3000.00m;
// Constructor:
public Employee(string name, string alias)
{
// Use this to qualify the fields, name and alias:
this.name = name;
this.alias = alias;
}
// Printing method:
public void printEmployee()
{
Console.WriteLine("Name: {0}\nAlias: {1}", name, alias);
// Passing the object to the CalcTax method by using this:
Console.WriteLine("Taxes: {0:C}", Tax.CalcTax(this));
}
}
public class Tax
{
public static decimal CalcTax(Employee E)
{
return (0.08m*(E.salary));
}
}
public class MainClass
{
public static void Main()
{
// Create objects:
Employee E1 = new Employee ("Kamal Khan", "Kami");
// Display results:
E1.printEmployee();
}
}

Output
Name: Kamal Khan
Alias: Kami
Taxes: $240.00

Abstract Classes

Abstract classes are a special type of base classes. In addition to normal class members, they have abstract class members. These Abstract class members are methods and properties that are declared without an implementation. All classes derived directly from abstract classes must implement all of these abstract methods and properties.

Abstract classes can never be instantiated. This would be illogical, because of the members without implementations.So what good is a class that can't be instantiated? Lots! Abstract classes sit toward the top of a class hierarchy. They establish structure and meaning to code. They make frameworks easier to build. This is possible because abstract classes have information and behavior common to all derived classes in a framework. Take a look at the following example:

abstract public class Contact // Abstract Class Contact.
{
protected string name;
public Contact()
{
// statements...
}
public abstract void generateReport();
abstract public string Name
{
get;
set;
}
}

Contact, is an abstract class. Contact has two abstract members, and it has an abstract method named generateReport(). This method is declared with the abstract modifier in front of the method declaration. It has no implementation (no braces) and is terminated with a semicolon. The Name property is also declared abstract. The accessors of properties are terminated with semicolons.

public class Customer : Contact // Customer Inherits Abstract Class Contact.
{
string gender;
decimal income;
int numberOfVisits;
public Customer()
{
// statements
}
public override void generateReport()
{
// unique report
}
public override string Name
{
get
{
numberOfVisits++;
return name;
}
set
{
name = value;
numberOfVisits = 0;
}
}
}
public class SiteOwner : Contact
{
int siteHits;
string mySite;
public SiteOwner()
{
// statements
}
public override void generateReport()
{
// unique report
}
public override string Name
{
get
{
siteHits++;
return name;
}
set
{
name = value;
siteHits = 0;
}
}
}

The abstract base class Contact has two derived classes, Customer and SiteOwner. Both of these derived classes implement the abstract members of the Contact class. The generateReport() method in each derived class has an override modifier in its declaration. Likewise, the Name declaration contains an override modifier in both Customer and SiteOwner.

C# requires explicit declaration of intent when overriding methods. This feature promotes safe code by avoiding the accidental overriding of base class methods, which is what actually does happen in other languages. Leaving out the override modifier generates an error. Similarly, adding a new modifier also generates an error. Abstract methods must be overridden and cannot be hidden, which the new modifier or the lack of a modifier would be trying to do.

The most famous of all abstract classes is the Object class. It may be referred to as object or Object, but it's still the same class. Object is the base class for all other classes in C#. It's also the default base class when a base class is not specified. The following class declarations produce the same exact results:

abstract public class Contact : Object
{
// class members
}
abstract public class Contact
{
// class members
}

Object is implicitly included as a base class if it is not already declared. Besides providing the abstract glue to hold together the C# class framework, object includes built-in functionality, some of which is useful for derived classes to implement.

Difference between Interface and Abstract Class

  • Interfaces are closely related to abstract classes that have all members abstract.
  • For an abstract class, at least one method of the class must be an abstract method that means it may have concrete methods.
  • For an interface, all the methods must be abstract
  • Class that implements an interface much provide concrete implementation of all the methods definition in an interface or else must be declare an abstract class
  • In C#, multiple inheritance is possible only through implementation of multiple interfaces. Abstract class can only be derived once.
  • An interface defines a contract and can only contains four entities viz methods, properties, events and indexes. An interface thus cannot contain constants, fields, operators, constructors, destructors, static constructors, or types.
  • Also an interface cannot contain static members of any kind. The modifiers abstract, public, protected, internal, private, virtual, override is disallowed, as they make no sense in this context.
  • Class members that implement the interface members must be publicly accessible.

Overriding Summery:

A derived class may override a virtual method of the base class with the keyword override. The following restrictions must be followed.

  • Keyword override is used in the definition of child class method that is going to override the base class's virtual method.
  • The return type must be the same as the virtual method have in base class.
  • The name of the method should also be same.
  • The parameter-list must also be same in order, number and type of parameters.
  • The accessibility of the overriding method should not be more restricted than that of the accessibility defined with virtual method of the base class. This accessibility either be the same or less restricted.
  • The virtual methods can be sealed in the child or derived classes to prevent further modifications in the implementation of the virtual method in the derived classes, by declaring them as sealed methods.

Hiding Base Class Members

Sometimes derived class members have the same name as a corresponding base class member. In this case, the derived member is said to be "hiding" the base class member.

When hiding occurs, the derived member is masking the functionality of the base class member. Users of the derived class won't be able to see the hidden member; they'll see only the derived class member. The following code shows how hiding a base class member works.

abstract public class Contact
{
private string address;
private string city;
private string state;
private string zip;
public string FullAddress()
{
string fullAddress =address + '\n' +city + ',' + state + ' ' + zip;
return fullAddress;
}
}
public class SiteOwner : Contact
{
public string FullAddress()
{
string fullAddress;
// create an address...
return fullAddress;
}
}

In this example, both SiteOwner and its base class, Contact, have a method named FullAddress(). The FullAddress() method in the SiteOwner class hides the FullAddress() method in the Contact class. This means that when an instance of a SiteOwner class is invoked with a call to the FullAddress() method, it is the SiteOwner class FullAddress() method that is called, not the FullAddress() method of the Contact class.

Although a base class member may be hidden, the derived class can still access it. It does this through the base identifier. Sometimes this is desirable. It is often useful to take advantage of the base class functionality and then add to it with the derived class code. The next example shows how to refer to a base class method from the derived class.

abstract public class Contact
{
private string address;
private string city;
private string state;
private string zip;
public string FullAddress()
{
string fullAddress =address + '\n' +city + ',' + state + ' ' + zip;
return fullAddress;
}
}
public class SiteOwner : Contact
{
public string FullAddress()
{
string fullAddress = base.FullAddress();
// do some other stuff...
return fullAddress;
}
}

In this particular example, the FullAddress() method of the Contact class is called from within the FullAddress() method of the SiteOwner class. This is accomplished with a base class reference. This provides another way to reuse code and add on to it with customized behavior.

Versioning

Versioning, in the context of inheritance, is a C# mechanism that allows modification of classes (creating new versions) without accidentally changing the meaning of the code. Hiding a base class member with the methods previously described generates a warning message from the compiler. This is because of the C# versioning policy. It's designed to eliminate a class of problems associated with modifications to base classes.

Here's the scenario: A developer creates a class that inherits from a third-party library. For the purposes of this discussion, we assume that the Contact class represents the third-party library. Here's the example:

public class Contact
{
// does not include FullAddress() method
}
public class SiteOwner : Contact
{
public string FullAddress()
{
string fullAddress = mySite.ToString();
return fullAddress;
}
}

In this example, the FullAddress() method does not exist in the base class. There is no problem yet. Later on, the creators of the third-party library update their code. Part of this update includes a new member in a base class with the exact same name as the derived class:

public class Contact
{
private string address;
private string city;
private string state;
private string zip;
public string FullAddress()
{
string fullAddress =address + '\n' +city + ',' + state + ' ' + zip;
return fullAddress;
}
}
public class SiteOwner : Contact
{
public string FullAddress()
{
string fullAddress = mySite.ToString();
return fullAddress;
}
}

In this code, the base class method FullAddress() contains different functionality than the derived class method. In other languages, this scenario would break the code because of implicit polymorphism. However, this does not break any code in C# because when the FullAddress() method is called on SiteOwner, it is still the SiteOwner class method that gets called.

This scenario generates a warning message. One way to eliminate the warning message is to place a new modifier in front of the derived class method name, as the following example shows:

using System;
public class WebSite
{
public string SiteName;
public string URL;
public string Description;
public WebSite()
{
}
public WebSite( string strSiteName, string strURL, string strDescription )
{
SiteName = strSiteName;
URL = strURL;
Description = strDescription;
}
public override string ToString()
{
return SiteName + ", " +URL + ", " +Description;
}
}
public class Contact
{
public string address;
public string city;
public string state;
public string zip;
public string FullAddress()
{
string fullAddress =address + '\n' +city + ',' + state + ' ' + zip;
return fullAddress;
}
}
public class SiteOwner : Contact
{
int siteHits;
string name;
WebSite mySite;
public SiteOwner()
{
mySite = new WebSite();
siteHits = 0;
}
public SiteOwner(string aName, WebSite aSite)
{
mySite = new WebSite(aSite.SiteName,aSite.URL,aSite.Description);
Name = aName;
}
new public string FullAddress()
{
string fullAddress = mySite.ToString();
return fullAddress;
}
public string Name
{
get
{
siteHits++;
return name;
}
set
{
name = value;
siteHits = 0;
}
}
}
public class Test
{
public static void Main()
{
WebSite mySite = new WebSite("CSKU","http://www.csku.co.nr","CSKU Blog");
SiteOwner anOwner = new SiteOwner("M. Jawaid", mySite);
string address;
anOwner.address = "North Nazimabad";
anOwner.city = "Karachi";
anOwner.state = "Sindh";
anOwner.zip = "74700";
address = anOwner.FullAddress(); // Different Results
Console.WriteLine("Address: \n{0}\n", address);
}
}

Here's the output:
Address:
CSKU, http://www.csku.co.nr, CSKU Blog

This has the effect of explicitly letting the compiler know the developer's intent. Placing the new modifier in front of the derived class member states that the developers know there is a base class method with the same name, and they definitely want to hide that member. This prevents breakage of existing code that depends on the implementation of the derived class member. With C#, the method in the derived class is called when an object of the derived class type is used. Likewise, the method in the base class is called when an object of the Base class type is called. Another problem this presents is that the base class may present some desirable new features that wouldn't be available through the derived class.

To use these new features requires one of a few different workarounds. One option would be to rename the derived class member, which would allow programs to use a base class method through a derived class member. The drawback to this option would be if there were other classes relying upon the implementation of the derived class member with the same name. This scenario will break code and, for this reason, is considered extremely bad form.

Another option is to define a new method in the derived class that called the base class method. This allows users of the derived class to have the new functionality of the base class, yet retain their existing functionality with the derived class. While this would work, there are maintainability concerns for the derived class.

Sealed Classes

Sealed classes are classes that can't be derived from. To prevent other classes from inheriting from a class, make it a sealed class. There are a couple good reasons to create sealed classes, including optimization and security.

Sealing a class avoids the system overhead associated with virtual methods. This allows the compiler to perform certain optimizations that are otherwise unavailable with normal classes.

Another good reason to seal a class is for security. Inheritance, by its very nature, dictates a certain amount of protected access to the internals of a potential base class. Sealing a class does away with the possibility of corruption by derived classes. A good example of a sealed class is the String class. The following example shows how to create a sealed class:

public sealed class CustomerStats
{
string gender;
decimal income;
int numberOfVisits;
public CustomerStats()
{
}
}
public class CustomerInfo : CustomerStats // error
{
}

This example generates a compiler error. Since the CustomerStats class is sealed, it can't be inherited by the CustomerInfo class.The CustomerStats class was meant to be used as an encapsulated object in another class. This is shown by the declaration of a CustomerStats object in the Customer class.

public class Customer
{
CustomerStats myStats; // okay
}

Polymorphism

Polymorphism is reflected in the ability to write one routine that can operate on objects from more than one class-treating different objects from different classes in exactly the same way. For instance, if both Customer and Vendor objects have a Name property, and we can write a routine that calls the Name property regardless of whether we're using a Customer or Vendor object, then we have polymorphism.

A vehicle is a good example of polymorphism. A vehicle interface would only have those properties and methods that all vehicles have, a few of which might include paint color, number of doors, accelerator, and ignition. These properties and methods would apply to all types of vehicles including cars, trucks, and semi-trucks.

Polymorphism will not implement code behind the vehicle's properties and methods. Instead, polymorphism is the implementation of an interface. If the car, truck, and semitruck all implement the same vehicle interface, then the client code for all three classes can be exactly the same.

C# gives us polymorphism through inheritance. C# provides a keyword virtual that is used in the definition of a method to support polymorphism.

Child class are now free to provide their own implementation of this virtual method, that is called overriding. The following points are important regarding virtual keyword:-

If the method is not virtual, the compiler simply uses the reference type to invoke the appropriate method.

If the method is virtual, the compiler will generate code to checkup the reference type at runtime it is actually denoting to, then the appropriate method is called from the class of the reference type.

When a virtual method is called, runtime check (late method binding) is made to identify the object and appropriate method is invoked, all this is done at runtime.

In case of non-virtual methods, this information is available at compile time, so no runtime check to identify the object is made, so slightly efficient in the way non-virtual methods are called. But the behavior of virtual method is useful in many ways; the functionality they provide is fair enough to bear this slight loss of performance.

Implementing Polymorphism

The key factor here is the ability to dynamically invoke methods in a class based on their type. Essentially, a program would have a group of objects, examine the type of each one, and execute the appropriate method. Here's an example:

using System;
public class WebSite
{
public string SiteName;
public string URL;
public string Description;
public WebSite()
{
}
public WebSite( string strSiteName, string strURL, string strDescription )
{
SiteName = strSiteName;
URL = strURL;
Description = strDescription;
}
public override string ToString()
{
return SiteName + ", " +URL + ", " +Description;
}
}

When we inherit above class, we have two choices to invoke constructor of the class. So this is an example of design time polymorphism. Here at design time we have to decide which method we need to invoke while inheriting the class.

Polymorphism is the capability of a program to carry out dynamic operations by implementing methods of multiple derived classes through a common base class reference. Another definition of polymorphism is the ability to treat different objects the same way. This means that the runtime type of an object determines its behavior rather than the compile-time type of its reference.