C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




What is shadowing?


Posted Date: 09 Jun 2008      Total Responses: 4

Posted By: Goutham Anand       Member Level: Gold     Points: 1


Can anyone explain me what shadowing means and how do we achive it in .net?



Responses

Author: Ravichandran    09 Jun 2008Member Level: GoldRating:     Points: 2
Public Class Parent

Public x As Integer = 10

End Class



Public Class Child

Inherits Parent

Public x As Integer = 20

End Class

I defined two classes, "Parent" and "Child," where "Child" gets inherited from "Parent." If I create an object (instance) with respect to "Parent" and access the field (x) as follows, there is no doubt that it displays "10."

Dim obj As New Parent

MessageBox.Show(obj.x)

However, if I create an object with respect to "Child" and access the field (x) as follows, the confusion starts:

Dim obj As New Child

MessageBox.Show(obj.x)

The class "Child" is equipped with the same field (x) twice -- one inherited from "Parent" and one of its own. If such a situation occurs, the field in the "child" shadows the field in "parent." In other words, the child member temporarily hides the parent member and activates its own. This is called shadowing.



Author: Binu Appukuttan    09 Jun 2008Member Level: GoldRating:     Points: 2
When two elements in a program have same name, one of them can hide and shadow the
other one. So in such cases the element which shadowed the main element is referenced.
Below is a sample code, there are two classes “ClsParent” and “ClsShadowedParent”. In
“ClsParent” there is a variable “x” which is a integer. “ClsShadowedParent” overrides
“ClsParent” and shadows the “x” variable to a string.


example


Public Class ClsParent
Public x As Integer
End Class
Public Class ClsShadowedParent
Inherits ClsParent
Public Shadows x As String
End Class


Author: asdf    12 Aug 2008Member Level: SilverRating:     Points: 0
• Shadowing
It won’t replace existing methods.
But replace the variations.
It leaves subclass as single version of the method.



Author: Satyanarayan SushilKumar Bajoria    21 Sep 2008Member Level: DiamondRating:     Points: 5
Hi,

Shadowing:
When two elements in a program have the same name,one of them can hide and shadow the other one.So in such cases the element which shadowed the main element is referenced.

For example:

public class ClsParent
public x as Integer
End class
public class ClsShadowedParent
inherits ClsParent
public shadows x as string
End class

Regards
S.S.Bajoria



Post Reply
You must Sign In to post a response.
Next : how to convert binary image to URL path
Previous : datalist
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

it help desk

Contact Us    Privacy Policy    Terms Of Use