Archive for the ‘Tech-Tips’ Category

How to use IS and AS keywords in C#

Using as keyword

Dynamic polymorphism which is evaluated at run time not at compile time so we are sure that errors are not known before execution. Like e.g Explicit casting is evaluated at run time.

object test = new Manager();
//You cant cast test to a Department!
Department dept= (Department) test;

So how can we safely use such casting and handle exception

Department dept = (Department) test;
catch(InvalidCastException ex)

Above code is about handling exception but how about doing some more logical coding in the failed case, coding into catch not good example.

We can determine whether the given type is compatible with another using ‘as’. Compatibility check will return null value.

Using is Keyword
Unlike as keyword is keyword returns false if compatibility between objects or casting failed.

void(Employee emp)
if(emp is Department)
     Console.WriteLine("Sorry, emp is not Department..");

Here we are checking runtime what incoming base class reference is actually pointing in memory. So we are not using try catch as well here to wrap the casting.

Happy programming..

Number of View :7860

No Comments

Interface Programming tool A Concept

Interface is technique or concept which is used to add set of behavior or functionality to be mandatory. When we derive into class then class has to implement each thing that is in Interface. Something like making skeleton and then giving different look and behavior using that skeleton. Decoupling of object and  its implementation is possible because of interface.

Lets say you create interface of Cycle

Interface ICycle
void Handle(); 
void Wheels(); 

Inheriting class

class AtlasCycle: ICycle
void ResizableHandle()
void fourDiaWheels()


Above cycle skeleton can be used to derive any brand of bicycle with different feature values.

  • Interface has by default all fields, properties and methods Public. But you can have internally private and use it appropriately inside interface.
  • One which is public has to be implemented in inheriting class So it better than having base class.
  • Class can inherit as many as interfaces So structures can also use interfaces.
  • Interface does not have implementation only declarations.
  • It is highly used to design architecture. So it is architecture job to define what to be exposed and what not to client.

Happy Programming..

Number of View :7453

No Comments

C# Language Features OOPS .NET

Quick walkthrough on C# features.


Object Types: It is parent type of all other known types in .Net. If used as an argument in Method call then passing any type to method will cause late binding assignment to that argument.
Value and Reference Type: This type categorized on the storage of value in memory. Value Type are stored in Stack. e.g type INT, DOUBLE.
Reference types are stored in heap. e.g Type String and Object.
Converting value type into reference type called as Boxing and reverse is UnBoxing.

C# allows simple and component variable declaration.

It is declared as set which are mapped to integers. This type allows us to have series which can have their mapping to unique integer value inside the set.

public enum EmployeeRole{ Trainee=0, Programmer=1, Sr Programmer=2}


Arrays: This type holds list.

int [] intArray;


OPERATORS Representing symbols for operations.
e.g Arithmetic[+, _, +], Logical[||, &&], String Concatenate[&], Increment and Decrement[+=], Comparison[<=, =>], Cast[()] etc..

FLOW CONTROL Controls the flow of your programme. e.g conditional statement [if ..else, switch], loops[while, do..while, for, foreach], functions.

CLASSES Class is type which includes all types, members, methods etc. It has visibility, its lifetime, relation, inheritance, method overloading..

REFLECTION Dynamically gather information of underlined type in late bound fashion. e.g Attributes allows to attach metadata to class and its members.

INTEROPERABILITY This feature facilitates to work with other programming language and API.
COM INTEROPERABILITY: This allows to integrate legacy components with .Net classes.
INVOKING WINDOWS API: This is same as VB6 feature to invoke and use windows API. Reference dll and create wrapper functions.

private static extern int MessageBoxA(int hwind, string Message, string caption, int Type);


STRUCTURED ERROR HANDLING This is way of handling error by blocking code. e.g



C# PREPROCESSOR This feature allows programmer to do better programming like expanding code, collapsing code…

Happy programming..

Number of View :6833


No Comments

Microsoft office 2007 OneNote How to use OneNote?

First Lets understand OneNote. What is OneNote? It is one of information capturing service or feature of Microsoft Office 2007. Capturing notes, saving notes, browsing your notes and also sharing notes is all possible with our regular paper notebook.. Here is the difference, Its all that what we have been doing for taking notes in office or any other place and writing information into our NoteBook and In one OneNote it is mobile, we can carry anywhere and share anywhere. What is special in OneNote, well you can carry your text capturing device anywhere so you have onenote that device whether its smartphone or digital notebook, windows phone , Second its office features, graphics and speed So you can carry it anywhere and share it. Unlike Paper you can copy info from other files, you can copy , create images and save it in page.

For onenote you can work offline or work online.

Onenote has text, Image, video , audio capturing features.
You can create your own template and customize it.
Can share notes with others.
You can use notebook multiple computers.

How to Use OneNote?
You need to install Office 2007 for better features.Latest you have Office 2013 Onenote.
Then you can start working with OneNote right away. Detail information can be found at office site of microsoft

Number of View :2730

No Comments

Buzz Windows Azure HDInsight Service Hadoop Big Data

What is upcoming in microsoft? What is latest in Microsoft Winodws Azure -HDInsight?

So what is HDInsight?

Haddop Insight is Apache hadoop service available on azure cloud. This is also dealing with big data which is nothing but managing data, enriching, and refining data virtually. Big data can deal data for personnel, organization and global. HDInsight provides HDFS and Mapreduce softwares available in azure in better way. It has Hive console and Javascript console which we can use for configuring, execution of Hadoop jobs.

So now you must have understood that to work with HDInsight you need Winodws azure storage account and pay for it so that you get maximum feature use.

You can learn more about it

More about Big data

Happy Learning..

Number of View :2656

No Comments

ViewState and Server Controls ASP.NET PageLifeCycle

How does view state data value assigned to controls on Html form or How user inputs value retained after post back.

This is all above comes in PageLifeCycle and we can find many articles on that. I have small understanding on very important thing and I would like share..

When Post Back happens or any server side event fired their are major event which plays role to retain data of view state.
LoadPostBackData – This function is only applicable for Postback. When the page is given to engine with all markup engine calls for several functions to complete the server side load.
Browser on event firing or postback will pass on the values to ASP.NET engine using HTTP POST header which actually has _VIEWSTATE.
IPostBackDataHandler interface will take care of calling LoadPostdata function for all the server controls for which loading view state is applicable.All listed controls in IPostBackDataHandler will have call for LoadPostdata () method like textbox, listbox. So here we can see that its not viewstate which is only responsible for loading user input to controls.

Page Load – In this event the load view state happens along with post back data.

Save View State -In this stage Page class construct View State for page which has to be maintained across post back. It is called according to the hierarchy defined in Page Instantiation for all the controls(stored in the WINDOWS\Microsoft.NET\Framework\version\Temporary ASP.NET Files).

Very nice explanation of page life cycle and role of view state is written here

Happy programming..

Number of View :2487

No Comments

Understanding the Object Oriented Programming

In .net the object plays role everywhere even if you directly code or do not object has its existence.
I have small program which was Interview Question at Microsoft.
C# code and understand the life of object.

Open Visual Studio -> New Project->Select c# and then Select Console Application

Name project – ObjectLifeCycle

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ObjectLifeCycle
    public class log
        public Int32 i;

        public void TestA(log obj)
            obj.i = 100;

        public void TestB(log test)
            test = new log();
            test.i = 1000;
    class Program
        static void Main(string[] args)
            log o = new log();
            o.i = 10;




You can directly paste this code in your .cs file and execute the code , you should see output as followed

So the object of class log which has only one variable in it and methods which has argument passed as its own object is having different scope in different assignment.

In Main Method object is initialized with values first time so first writeline statement gives 10.
Second method call TestA with object o is passed. Inside the method their is just reassign of value to int as 100 so the value 10 is replaced to 100 for object o which is still having same reference.

Third method call TestB in which again object o is passed which had value of int as 100. Now inside method new object initialization happens that means new object o for which int value is 1000.
Now you must be wondering third value is not 1000, this is because TestB created new object with new memory allocation. So test object scope finished ones it came out of the method. Since the Writeline method is calling value available in object o it has given 100.

Lets do one more change on line 35

o.i = o.TestB(o);


In above case what is happening is we are copying return value of int from TestB method and assign it to object o.i int value. of course TestB return type has to be changed from void to int.

It should return

For more details

Happy programming….

Number of View :2502

No Comments

Windows azure Cloud .Net Applications

Hmm. . Starting late when Microsoft has already come up with most of the latest versions on their own Cloud that is Windows Azure.
Today I got time to go through some of the videos available in MSDN and came to know how cloud works in Windows Azure providing extensions to all available application templates which are heavily used like ASP.NET, Windows Forms, MVC, WCF, SQL. Watching videos gives feeling that Cloud or Windows Azure is simple and I can straight away go ahead create my application in Azure but I am beginner in this so hurdles are sure in starting.

So what I have faced and How I Solved
Problem: I could not get Windows Azure SDK installed on VS 2010 ultimate version.
Reason: Error specified that I had nugets of MVC3 updates installed which are not compatible. It means still some more opportunities to Microsoft for giving fix or Patch.

It is true that I installed MVC4 not MVC3 but it had latest updates which I installed from Nugets option available in VSTF Extension Manager under tools. Why this issue? I am not sure.

I would like to share what I learnt in Videos

Setup environment for Windows Azure by installing Windows Azure SDK latest version 1.8
Create new application under Cloud same way you create without using cloud.
Publish it using options available in properties.
Host it in Windows Azure using your lab account if you do not have it create Trial one.
Deploy it on Windows Azure region.
Execute or Browse it.

If I am not wrong Cloud concept is available from the time Domain has come into picture. Some one is providing domain as well as host server environment and user is just publishing deploying the package.
But Cloud is more advanced gives you more features which are important for Development team like Building, Configuration, Different Data Source management, Versioning many more.

Now above all steps are possible if you are already familiar with .NET.

Lets go back to the problem I had and solution
So here is the solution I followed.
I read FAQ and googled it but could not get the working solution where I can keep MVC4 and then Install Windows Azure. If anyone reading this article and found right solution please do comment.

Solution: I uninstalled MVC4 not from nugets but from Control Panel and then Installed Windows Azure SDK. It worked.

Happy Troubleshooting..

Number of View :5620

No Comments

HTTP Error 500.21 – Internal Server Error, Solution

HTTP Error 500.21 – Internal Server Error
Handler “PageHandlerFactory-Integrated” has a bad module “ManagedPipelineHandler” in its module list

I received above error when I tried to include my ASP.NET application into IIS 7 and browse it. This because of the handlers missing for specific version of Microsoft Dotnet Framework in your IIS 7. I had installed visual studio 10.0 and later I installed IIS 7 So IIS did not pick up all the handlers required for running application built in ASP.NET 4.0 or .NET 3.5 framework. Every time I browse any page of the application from IIS it shows only error with index 500.21, 500.19 ..

Now here is solution you can try out,
Step 1: Check the Control Panel->Programs->Windows features on or off (This is in your WINDOWS 7  OPERATING SYSTEM)
Step 2: Ones you see list of all features in the popup check for Internet Information Services features and should have check-box enabled for ASP.NET.
Step 3: You can now try the following command on your Visual Studio command prompt,

%windir%\Microsoft.NET\Framework\v4.0.21006\aspnet_regiis.exe -i

Note: Make sure you opened the command prompt using ‘Run as Administrator’. While doing above operation you should close all instances of Visual Studio IDE, tools.

This will add all handlers in IIS 7 and try browsing the page you should get the page without error.
You should also check that your application pool is targeted to use appropriate framework version.

Happy troubleshooting..

Number of View :6782

No Comments

Basic Standard Action Tags In JSP Tutorial With Examples JSP Technical Advices

Standard Action Tags In JSP

Standard Action Tags In JSP are meant for performing some action at run time. As the name of the tag itself suggests these tags are used for run time behavior. Unlike scripting tags which are meant for generating related servlet code at the time of translation,Standard Action Tags In JSP generates code for run time behavior.


Examples of Standard Action Tags In JSP are as follows :


  1. <jsp:include file= ”AnotherJsp.jsp”/>
  2. <jsp:forward file=”AnotherJsp.jsp”/>
  3. <jsp:useBean id=”obj” type=”SomeBean” class=”SomeBean” scope=”request”>
  4. <c:set var=”attrName” value=”attrVal” scope=”request”/>


There are so many other tags as well amongst which these are some and important.

Let us take these tags individually as see how do they contribute for Standard Action Tags In JSP


  1. <jsp:include file= ”AnotherJsp.jsp”/> : This tag is used for run time inclusion of another JSP page in an existing one. This inclusion is not similar to inclusion with include directive. Include directives are meant for static inclusion. This means that the code from the included JSP will be included int the including JSP at the translation time. But in the case of <jsp:include file= ”AnotherJsp.jsp”/> tag a run time call to the included JSP is done and the response from the included JSP is added to the response of the including JSP.
  2. <jsp:forward file=”AnotherJsp.jsp”/> : This tag is used for forwarding the request to another JSP at run time. The difference here from run time or dynamic inclusion is that here the response from the forwarded JSP only goes to the user and the response from the first JSP from where the forward happens gets flushed out.
  3. <jsp:useBean id=”obj” type=”SomeBean” class=”SomeBean” scope=”request”> : This tag is used to create or fetch a java bean object ,set or get its property value/s and retrieve or set this java bean object in certain scope.
  4. <c:set var=”attrName” value=”attrVal” scope=”request”/> : This tag is used to set an attribute in a particular scope.This is an important tag as our MVC applications rely heavily on attributes
Number of View :4989

Tags: , , , , ,

No Comments

Content Protected Using Blog Protector By: PcDrome.