Saturday, 12 April 2014

Enums in C#

An enum is kind of construct that you can use to make your code easier to work with. The enum construct is useful when you want to create a method that has multiple modes. A good example is the constructor for the CryptoStream class. The CryptoStream constructor accepts CryptoStreamMode.Read or CryptoStreamMode.Write as one of its arguments. This is a simple enum.

Enum is short form enumerator. Enumerating something literally means assigning numbers to it. An enum takes meaningful names and assigns numbers to them.

An enum object doesn't take up any more memory than a standard int variable, so there is no good reason not to use them to make your code clearer and easier to understand. As well as making your code more readable, enums also make methods easier to use; this makes them particularly useful in class libraries.

Friday, 11 April 2014

Garbage Collector

The Garbage Collector is a special feature of C# that automatically clears objects from memory when they are no longer needed. For example: once a method is finished executing, the garbage collector removes any variables it used from the memory. Thanks to the garbage collector it is very rare for C# applications to suffer from memory leak issues when the program uses up more and more memory until it overloads the system.

The garbage collector will work automatically without you needing to do anything but you can send commands to it by using the GC class. The GC class can also provide some useful information about memory usage.
It is important to note that using the GC class can potentially make your project less memory efficient. The garbage collector files your objects into one of three categories or generations.

Generation 0 contains objects that will be disposed off quickly such as variables within methods. Generation 1 contain objects that are expected to remain in memory for longer, a public property of a class might be a generation 1 object. Generation 2 contains objects that are expected to remain in memory for a very long time such as static classes.

When the garbage collector cleans up memory, it promotes any object that is still in use to the next generation. Misusing the GC class can lead to objects being promoted to inappropriate generations and remaining in memory for longer than they should.

Monday, 7 April 2014

Difference between Class and Struct

A struct is a construct that is almost identical to a class.
The major difference is that structs are value type objects while classes are reference type objects. This means that when you pass a struct object to a method, the method will receive a copy of the object and wont be able to make changes to it outside the method.
It is usually best to use classes instead of structs as there are many features of classes that aren't supported by struct objects. However it is not possible to pass a class object by value so if there is s special need to do this you may find struct more appropriate.

The limitations of structs are that they cannot have constructor methods without any arguments and they cannot extend classes nor can classes extend structs.

Because structs are value type objects, this means that they are stored in the stack. Whereas class objects are stored in the heap. Because struct objects are stored in the stack they will generally be slightly faster than class objects. It is best to avoid using large structs as there is a limited amount of space in the stack, you should only use structs for small constructs that need to be accessed quickly.

Sunday, 6 April 2014

C# Lazy Class

When you create a variable in C# it immediately reserves a space in memory even if you don't assign a value to it. For example: if you create an int variable it immediately reserves 32 bit of memory. It is very rare for this to be an issue but there may be cases when you need to work with a class that consumes enormous amount of memory.

In these cases you can use the Lazy class to prevent the object from being loaded into memory until it is needed. This is called Lazy instantiation. If you follow good coding practices, its extremely unlikely that you'll ever need to make use of the lazy class.

An important note when working with Lazy objects is that their constructor methods will not run until they are loaded into memory.

Friday, 4 April 2014

C# Tuple Class

The Tuple class is a new feature of ASP .NET 4.0 that enables you to very quickly create custom data structures similar to classes. Tuple objects can't contain methods, they are only structures for data storage. It is best practice to avoid using Tuple as where possible as they don't have the flexibility of real classes and can make your code harder to understand.

Tuple objects offer an easy way to return multiple values from a method. It is important to note however that it is better to do this using either the out keyword or ideally returning a custom class.
Tulple objects have a limit of eight properties, although you can nest Tuple objects by using Tuple as a property type within another Tuple. You need to set the values of a Tuple object's properties when you create it. After the Tuple object has been created it's values will be read only.
Once a Tuple object is created, it will behave in exactly the same way as any other object that has read-only properties.

As well as creating a Tuple object using the standard method of instantiating a class, you can also use the Tuple.Create method. The only reason to use this method is to cut down on the amount of code you need to type as the Create method will automatically select the correct data types for the values you provide.

Thursday, 3 April 2014

ASP .NET Master Pages

A Master Page is a way of storing your site layout in a single file which you can then assign to many pages. The site that is automatically generated when you create a new ASP.NET web application includes a master page. By using a master page you can avoid having to manually update each page when a minor change is made to your site layout.
The disadvantage of master pages is that you lose the ability to completely customize each page.

The ContentPlaceHolder is a special control that is only available on master pages. It is used to define areas that can be edited on pages that use the master page. The ContentPaceHolder appears in the standard category of the toolbox.

Tuesday, 1 April 2014

Difference between Web Application Project and Website Project

Web Application projects are generally a better option then website projects for two reasons: Firstly because website projects are not compiled; the web server has to compile them as the site is viewed, this makes websites slightly slower then web applications.
Secondly because web application projects are compiled; so the code of the website they produce will not be easy to edit, this prevents the website from being tampered with and allows you to protect your source code.

In your professional career you might have to work on a website project that was created by another developer, in this case it is useful to convert it into a web application project.

Monday, 31 March 2014

Why C# is a Type-Safe Language

"It is impossible to write unsafe code in C#". Some programmers think that this statement is not 100% correct but it is correct and C# is definitely a type-safe language.

C# enforces its variable types very strongly for ex: this means that C# is always aware that an int variable will contain a whole number and nothing else; because of this C# is considered a type-safe language. Some other programming languages allow variable to be created without fixed data types which can lead to errors that are very hard to debug.

Saturday, 29 March 2014

Global.asax

Global.asax contains event handlers that are related to your applications and user sessions. Global.asax also contains an event handler that runs whenever an error happens anywhere in your application. By using Global.asax you can intercept every error that happens on your site. There are other event handlers in Global.asax that can also be useful.

Application_Start:
Runs when your site is started by the web server.

Application_End:
Runs when your site is stopped by the web server.

Application_Error:
Whenever there is a server error on your site.

Session_Start:
Runs when a user arrives at your site and start a new session.

Session_End:
Runs when a user session ends.

The most likely use of the Session_Start and Session_End events would be to log details of users when they arrive at your site.

You can also add other event handlers to Global.asax. There are many other application events that Global.asax can handle. A useful example is the Application_AuthenticateRequest event which runs before any page is served to a user, some programmers use this to implement their own custom login systems when they have special requirements that go beyond the built-in security features.

Friday, 28 March 2014

Stored Procedures

Store Procedures are similar to methods but are stored inside the database. Store Procedures contains SQL code that can manipulate data in ways that would be difficult using C#. In a team environment store procedures are usually written by the DBA.

Store Procedures can have arguments and return values just like any other method. Store Procedures can do everything LINQ can do and usually be faster and more efficient. Using Store Procedures for everything might seem ideal but having hundred's of store procedures in a database often becomes unmanageable and difficult to maintain. I recommend using LINQ for simple everyday queries and store procedures for anything more complicated or if you see performance issues.

Using Store Procedures centralizes your SQL code on the database server and makes it easier to maintain your code if the database changes.

Thursday, 27 March 2014

Collections Vs. Arrays

Collections are a more advanced way of storing multiple values inside a single object. Unlike arrays which have a fixed size once they are created, you can add and remove items from collections.
For most purposes collections are more convenient to work with then arrays.

Monday, 24 March 2014

How to Configure Default Routing


We are given the above topology and we have to implement the following:

  1. Create default route on ISP router to the RISE STAR Enterprise Company. 
  2. Apply command show ip route to verify your configuration. 
Default Routing is very similar to the Static Routing as the pattern of configuring the Default Routing is identical to the Static Routing.

Now to start, click the ISP router and go to the CLI tab and type the following:

ISP>en
ISP#conf t
ISP(config) #ip route 0.0.0.0 0.0.0.0 se0/0/0
ISP(config) #ex
ISP#

Now click LAB_A router, go to the CLI tab and type the following:

LAB_A>en
LAB_A#conf t
LAB_A(config) #ip route 0.0.0.0 0.0.0.0 se0/0/0
LAB_A(config) #ip route 0.0.0.0 0.0.0.0 se0/0/1
LAB_A(config) #ex
LAB_A#

Now click on LAB_B router and go to the CLI tab and type the following:

LAB_B>en
LAB_B#conf t
LAB_B(config) #ip route 0.0.0.0 0.0.0.0 se0/0/0
LAB_B(config) #ip route 0.0.0.0 0.0.0.0 fa0/0
LAB_B(config) #ex
LAB_B#

Finally click on LAB_C router and go to the CLI tab and type the following:

LAB_C>en
LAB_C#conf t
LAB_C(config) #ip route 0.0.0.0 0.0.0.0 fa0/0
LAB_C(config) #ex
LAB_C#

Note that the first address(0.0.0.0) is used for the default address and the second(0.0.0.0) is used for the default sub-net mask and fa0/0 is the next hop address.
The task 1 is completed here.

Now the second task is to verify the configuration. To do this simply go to every router one by one and type the command show ip route in the CLI tab as shown below:


As you can see in the highlighted area the default routing is configured. If this line does not appear, it means you have not configured the routers correctly.

Sunday, 23 March 2014

LINQ

Stands for Language Integrated Query. LINQ is a relatively new addition to .NET which makes working with databases much easier.

Before LINQ, programmers would usually create their own set of classes to generate the SQL needed to interact with the database, this took a lot of time and effort. ASP.NET's LINQ classes automatically create the SQL needed to interact with your data making it unnecessary to learn SQL. LINQ also streamlines the development process by removing the need to create your own data access classes.

It is important to note that although it is very easy to create LINQ data classes, they do not automatically update when the structure of a database changes; by structure I mean the design of the database not the data that is held inside it. The only way to update LINQ data classes is to recreate the entire dbml file, you can do this by simply deleting the old file and creating a new one. In theory it is possible to refresh individual items but I have found that this occasionally causes problems that prevent the project from building. For this reason I recommend that you always recreate the entire dbml file if your database structure changes.

Before LINQ, databases were usually accessed using the System.Data.SqlClient namespace of the .NET Library. System.Data.SqlClient is still available but it requires a lot more code to use. This method also requires you to either use Store Procedures or SQL code. LINQ has made System.Data.SqlClient obsolete but you may still see it being used in older projects.

Saturday, 22 March 2014

DES Key Generation

Download the DES Key Generator to generate the Key with the help of Sub-Key.
Click the Link below to download the DES Key Generator.

DES Key Generator

DES Sub-Key Generation

Download the DES Sub-Key Generator to generate the Sub-Key 1 and Sub-Key 2 with the help of Key.
Click the Link below to download the DES Sub-Key Generator.