Wednesday, November 25, 2015

Overloading and Overriding in C# with example

Background

Mostly people are confused in object oriented concept that is Overloading and Overriding and interviewer take a benefit and make it complicate for them. Here, I will start for Overloading and Overriding from its root level as every beginner or expert can under stand this concept.

What is Method Overloading? 

Class can have multiple method with same name and different signature and type is called Method overloading. It is example of compile time polymorphism which is done at compile time. This is the basic definition about method overloading but now we'll how we can achieve it in our programming, there are several ways to achieves which are listed as below.

Steps to achieve Method overloading.
  • By changing the number of parameter in method signature.
  • By change parameter datatype in signature
  • By changing parameter order in signature
       

So, as display in above image we can create multiple method with same name but different signature and data type this called as method Overloading or you can call it as a Compile time polymorphism as well.

Here, before moving to our next topic I like to discuss one thing that is sometimes in interview interview is asking question like

Question -  if in class ther are two method with same name and signature but they having different return type, so is it call as method Overloading or not ?

Answer for this question is No, its notmethod overloading as both method having same parameter, so it will be conflict in between two methods.

In overloading there is one more concept is there, it is Method Hiding concept.

In base and child class both having method with same name and same signature at that moment if you are running application so your application will run successfully but in Warning section you will find a warning that is, suggesting you to use new keyword before child class method. Please refer below image.


In above image you can clearly see that after running this project in warning section it gives warning for New keyword. So, for method hiding we are using new keyword in overloading concept.

Now, we will move to our next topic that is Method Overriding in C#.


Method Overriding


Based class and child class having method with same name, same parameter and same return type is called method overriding. It is example of runtime polymorphism.

Method overriding is only possible with child class where class having parent child relationship and where child class method is overriding base class method. So, in same method cannot do overriding. 

For method overriding we are using two key words, Virtual and Override.

In base class we are using virtual keyword and in child class override keyword that means child class method is overrides parent class method.



So, as display in image base and child class having same method with same signature and return type but we have override parent class method by adding Override keyword to child class method and adding Virtual keyword to base class method. 

I hope you enjoy learning of Overloading and Overriding concept through this examples and detail information of both concept.

Summary
I hope this article is useful for all beginners and programmers. If you have any suggestion related to this article then please give your comment, I'll give your comment answer. 


http://stackoverflow.com/questions/18251128/why-am-i-suddenly-getting-a-blocked-loading-mixed-active-content-issue-in-fire/33910550#33910550

Life Rocks: Mixed Content: The page at '………………' was loaded over HTTPS, but requested an insecure resource '…………….'. This request has been blocked; the content must be served over HTTPS.


Friday, January 30, 2015

Mixed Content: The page at '………………' was loaded over HTTPS, but requested an insecure resource '…………….'. This request has been blocked; the content must be served over HTTPS.


Mixed Content: The page at '………………' was loaded over HTTPS, but requested an insecure resource '…………….'. This request has been blocked; the content must be served over HTTPS.

Error - when user try to use infragistic grid with iframe in Chrome upper version that is version > 36 will definitely get error.

Solution - He use solution word is wrong for this as "Chrome" browser is currently try to resolved this bug in higher version.

Actually it start from my application, when I  was trying to sort my grid record in Chrome at that moment my page went blank and this issue happen so many time.

Finally, after research in development tool came to know it got error like below.

Mixed Content: The page at 'Your site1' was loaded over HTTPS, but requested an insecure resource 'Your site2'. This request has been blocked; the content must be served over HTTPS.

 


In above one where I wrote Your site1, at that place you will got your site name with https:// and in second Your site2 place you will got site name with http://. So, if you try with secure http in iframe in chrome browser with higher than 36 version than you will got error.

 But same thing is working properly with IE and Firefox in any version .
For further you will visit below link, so you will get proper help from Chromie blog.
Please don't forget to put your comment.


Tuesday, March 5, 2013




Health tips for remove both stress and weight loss .......


Hello friend  my today blog is related to the health and after concern so many people and their day to day life    style I come to conclusion that every one hectic schedule make us robot.

How to make your self relax from this hectic schedule and  how you will be full energy through your whole day work? Solution of all this question is "Surya Namaskar" - Type of yoga.

Which will give you energy for the whole day work or its different steps help you to maintain your energy left through the whole day work.

Here are  steps for the Surya Namaskar and their benefits. 

Step - 1  


Stand with your feet together and palms folded in front of your chest. Close your eyes properly and chant the Mantra – Om Mitrayah Namaha . Then breathe normally.
Health benefits of it
Promotes balance, stimulates the respiratory system, exercises shoulder, back and neck muscles

Step - 2 
Raise your arms over your head and shoulders with the palms touching each other and biceps touching your ears. Stretch your abdomen as much as possible and lean backwards. Inhale and chant Om Khagaya Namaha.
Health benefits of it
Promotes balance, promotes digestion, exercises arms and shoulder muscles, tones the spine, promotes flexibility in back and hips

Step - 3 
Bend forward and place your palms at the side of your feet. Touch your knee with forehead and exhale deeply, while chanting Om Suryaya Namaha.

Health benefits of it
Promotes blood circulation, tones abdominal tracts, stretches back and leg muscles, stimulates spinal nerves, stimulates lymphatic system

Step - 4 
Take one leg back and place the other leg in the front with palms firm on the ground. Raise your head and inhale while chanting Om Bhanuvae Namaha
Health benefits of it
Exercises spine, strengthens hand and wrist muscles

Step - 5
Bring the leg that was in front next to other one and keep other one and keep the hips off the floor with both your hands supporting the body in a push up position. Exhale and chant Om Ravi Namaha.
Health benefits of it
Stimulates blood circulation, strengthens the heart, strengthens wrist and arm muscles, relieves neck and shoulder tension

Step - 6
Lower your knees, chest and forehead with your palms firmly on the ground next to your chest and elbows bent upwards. Hold your breath here and chant Om Pushnae Namaha.
Health benefits of it
Strengthens leg and arm muscles, increases flexibility in neck and shoulders, stretches arms, shoulder, neck and back muscles, exercises back muscles, releases tension in neck and shoulder

Step - 7
Lower your waist and raise your upper body. Look upwards and keep your arms straight. Then inhale at a slow pace and recite Om Hiranya- Garbhaya Namaha.
Health benefits of it
Stimulates circulation to abdominal organs, tones digestive tract, stretches upper and lower body, promotes flexibility in the back, stimulates nerves in spine

Step - 8
Raise your hips and bring your head to the floor with eyes on the navel and heel on the floor. This position will exactly look like an inverted ‘V’. Then as usual exhale and chant Om Marichiye Namaha.
Health benefits of it
Stimulates blood circulation, strengthens the heart, strengthens wrist and arm muscles, relieves neck and shoulder tension

Step - 9
In this step the posture is the same as the fourth step. Inhale and chant Mantra Om Adityaya Namaha.
Health benefits of it
Exercises spine, strengthens hand and wrist muscles

Step - 10
In this step the posture is the same as the third step. You need to exhale while hymning Om Savitre Namaha
Health benefits of it
Promotes blood circulation, tones abdominal tracts, stretches back and leg muscles, stimulates spinal nerves, stimulates lymphatic system

Step - 11
This stage is same as the second stage. Inhale and chant Om Arkaya Namaha
Health benefits of it
Promotes balance, promotes digestion, exercises arms and shoulder muscles, tones the spine, promotes flexibility in back and hips


Step - 12
This stage marks the final stage of Surya Namaskar and it is similar to the first stage. You have to breathe normally and recite Om Bhaskaraya Namaha here.
Health benefits of it
Promotes balance, stimulates the respiratory system, exercises shoulder, back and neck muscles



Friday, March 1, 2013

How to handle Null value in Query Expressions (in C# programming)


How to handle Null value in Query Expressions (in C# programming)



As all of us know as that in database it is tough to handle Null value with with DateTime, String and int datatype. 

Once upon time I also face problem with this in Linq with compile query, when I   tried to convert null value to Timespan datatype.


Here in below query I assigned all value in variable and each variable with 
different datatype as per it need.
 
int EmployeeId,
string EmployeeName,
System.Timespan StartTime,
System.Timespan EndTime,
string Address1,
string Address2,
string PostalCode,
string City, 
string State  

var query1=from e in Employees
           where e.EmployeeID != null
           select new 
           {
            EmployeeId = e.EmployeeID.Value,
            EmployeeName = e.EmployeeName,
            StartTime = e.StartTime.Value,
            EndTime = e.EndTime.Value,
            Address1 =  e.Address1,
            Address2 =  e.Address2,
            PostalCode = e.PostalCode,
City = e.City, State=e.State  
           }).FirstOrDefault()




Sometime when StartTime and EndTime  field come Null at that moment above one 
query give Exception for Null value.

For handling here we use conditional operator that is (?:).

for example : when we write If condition is in this manner.

If()
 }
else
}
for conditional operator (___? __ : __) in same manner we are using it in query expression. By using these how I will display my result and also convert Null value to the Timespan datatype.
Solution :
var strTimeSpan= "10.22 AM";
var query1=from e in Employees
           where e.EmployeeID != null
           select new 
           {
            EmployeeId = e.EmployeeID.Value,
            EmployeeName = e.EmployeeName,
            StartTime = (e.StartTime.Value == null ? TimeSpan.Parse(strTimeSpan) :e.StartTime.Value)
            EndTime = (e.EndTime .Value == null ? TimeSpan.Parse(strTimeSpan) :e.EndTime .Value),
            Address1 =  e.Address1,
            Address2 =  e.Address2,
            PostalCode = e.PostalCode,
City = e.City, State=e.State  
           }).FirstOrDefault()
By the use of TimeSpan.Parse(strTimeSpan) we can convert string to Timespan value

Please give your valuable feedback in comments and for any queries you can right here.



Sunday, December 27, 2009

How would you format Gridview in Asp.Net

GridView Examples for ASP.NET 2.0: Formatting it in .net for beginners  


Fortunately, all of these tasks are easy to accomplish with the GridView, most of which can be accomplished through the Design view without a line of code. There's even an Auto Format wizard to help improve the aesthetics of the GridView for folks like me who have no artistic skills. In this section we'll look at how to format the GridView through properties that can be set through the Designer, how to format based upon the actual data bound to the GridView, and how to use skins to alter the appearance of the GridView.

Examining the GridView's Aesthetic Properties

Like the DataGrid in ASP.NET 1.x, the GridView contains a wealth of properties that can be set to gussy up the appearance of the GridView. Properties such as BackColor, Font, and ForeColor allow you to dictate the aesthetics for the entire GridView. You can also specify aesthetic settings specific to particular parts of the GridView through the HeaderStyle, RowStyle, AlternatingRowStyle, FooterStyle, and other properties. Additionally, styles can be set on a column-by-column basis, as well.

If you are an artistic person you can likely put together proper colors and styles that will provide the end user with an eye-pleasing GridView. If you are like me, though, the good news is that the GridView can be Auto Formatted to a variety of well put together styles. To take advantage of the Auto Formatting, simply click the Auto Format link in the GridView's Smart Tag, which will display the Auto Format dialog box (shown in Figure 1).
Aa479342.gridview_fg11(en-us,MSDN.10).gif
Figure 1

The Auto Format wizard only applies various colors designs to the GridView. If you want to adjust the GridView column appearances—such as formatting the data as a currency or center-aligning the data—simply click the Edit Columns link from the GridView's Smart Tag. This will display a dialog box listing all of the GridView's columns and their properties (see Figure 2).


Aa479342.gridview_fg12(en-us,MSDN.10).gif
Figure 2

The lower left-hand corner lists the columns in the GridView. From this dialog box you can adjust the ordering of the columns or remove or add columns altogether. To reorder the columns in the GridView, click on a column and then click on the up or down arrow to adjust its position in the column list. To remove a column from the GridView, select the column then click the X button to delete it.
When you click on one of the columns, its properties are listed in the pane on the right. From the ItemStyle property you can set formatting properties for the items of the column, such as how the data should be horizontally aligned, or if the data should be displayed in a bold font. You can change the text that appears in the header of the column through the HeaderText property. To format the data in the columns, use the DataFormatString property, setting it to {0:format string}. For example, to have the UnitPrice column formatted as a currency, I set the DataFormatString property to {0:c}.

Figure 3 shows a screenshot of a formatted GridView displaying data from the Products table. Notice that the text in the headers has been changed from their default values to more user-friendly values. The GridView has also been given some color (I used the Brown Sugar option in the Auto Format dialog box), the Price/Unit and Units In Stock columns' data is right-aligned, and the Price/Unit column's data has been formatted as a currency.


Aa479342.gridview_fg13(en-us,MSDN.10).gif
Figure 3

Changing the GridView's aesthetic properties through the Designer simply sets the declarative syntax to the appropriate values. The complete declarative syntax for the page is shown here:"DataSourceMode="DataReader"     

Skinning the GridView

Two of the neat new features in ASP.NET 2.0 are Themes and Skins. A Skin is a file that defines the visual appearance of a particular control. You can create a Skin file for the GridView control that defines the look of the GridView for different SkinIDs. A Theme is a collection of Skins.

In order to start using Themes you must create a folder in the /app_themes directory of your Web application. Inside this directory, add a new folder for each Theme you want to create. In the download accompanying this article, there's a single folder in the /app_themes directory, GridViewTheme. Adding Skins to a Theme is as simple as adding a new file named WebControlToBeSkinned.skin in the Theme's directory (to provide a Skin for the GridView, name the file GridView.skin). The Skin file should contain declarative syntax specifying the aesthetic markup for the GridView for various SkinIDs. As the file GridView.skin shows, I have created a default markup and a markup for two SkinIDs: Professional and Fun.


The default markup is listed at the top, and indicates that the GridView should be displayed with the Arial font. The next two sections indicate the markup that should be used for the SkinIDs Professional and Fun. For Professional, the Verdana font is used with a CellPadding of 4 and a dark gray header background with white text. Each alternating row color's background is set to a light gray. For Fun, the Comic Sans MS font is used, with a larger font size and a brownish background.

Finally, to Skin a GridView, simply add the Theme to use in the @Page directive and then set the GridView's SkinID appropriately. The following page specifies the Theme in the @Page directive and then displays three GridViews: one with no SkinID specified, one with the Professional SkinID, and one with the Fun SkinID.

Figure 4 shows a screenshot of this page when viewed through a browser. Notice that the aesthetic formatting is applied to the three GridViews even though the corresponding settings aren't in the ASP.NET page's declarative syntax. Rather, the settings are being dynamically imported from the GridView Skin file for the specified Theme.



Aa479342.gridview_fg14(en-us,MSDN.10).gif
Figure 4

Formatting the GridView Based on the Underlying Data

In the two previous examples the GridView's formatting was specified statically. There are times, however, where you might want to alter the formatting based on the data in the GridView. For example, when listing product information you might want to draw the user's eye to products that are out of stock. One way to accomplish this would be to change the background color of those rows with a Units In Stock value of 0.

To accomplish this we need to inspect the data of each of the rows of the GridView and alter the row's BackColor property if the Units In Stock is 0. The GridView offers a RowDataBound event that fires once for each row after the row has been created and bound to the corresponding record of data from the data source control. We can create an event handler for this event that checks to see if Units In Stock is 0 and, if it is, set the BackColor property of the GridView row to Yellow.

To create an event handler for the GridView's RowDataBound event, go to the Design view, click on the GridView, and go to the Properties pane. From the Properties pane, click on the lightning bolt; this will list the GridView's events. Then, in the RowDataBound line, type in the name of the event handler you want to create (I named my event handler productsGridView_RowDataBound). Finally, enter in the following code into the event handler:

products GridView_RowDataBound Event Handler (Visual Basic)


Sub productsGridView_RowDataBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
   'determine the value of the UnitsInStock field
   Dim unitsInStock As Integer =  _
     Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, _
     "UnitsInStock"))
   If unitsInStock = 0 Then
       ' color the background of the row yellow
       e.Row.BackColor = Drawing.Color.Yellow
   End If
End If
End Sub

productsGridView_RowDataBound Event Handler (C#)

void productsGridView_RowDataBound(object sender,GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
         // determine the value of the UnitsInStock field
         int unitsInStock = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem,"UnitsInStock"));
        if (unitsInStock == 0)
             // color the background of the row yellow
            e.Row.BackColor = Color.Yellow;
    }
}


The event handler starts by checking to see if we are working with a DataRow. Realize that the GridView's RowDataBound event handler fires for each of the rows being created, including the HeaderRow. However, the HeaderRow doesn't have a Units In Stock column with data associated with it, so we are only interested in working with DataRows. The UnitsInStock field from the data bound to the GridView row is obtained through a DataBinder.Eval() call, passing in the data bound to the GridView row (e.Row.DataItem) and the name of the field whose value we are interested in. Finally, a check is made to see if there are zero units in stock. If so, the 
BackColor property of the row is set to Yellow.

Figure 5 shows a screenshot of this example when viewed through a browser. Note that rows with zero units in stock are highlighted yellow.


Aa479342.gridview_fg15(en-us,MSDN.10).gif
Figure 5