473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to change the name of property in derived class?

I have base class with some properties(variables).I want to inherit that class and want to change name of that properties in the derived class using concept of Shadowing.Is it possible??If yes then how??

Please help me out.
Jun 1 '12 #1
1 4499
Aimee Bailey
197 Expert 100+
C# does not provide a method for giving a different name to an inherited property, as derived classes are cast-able back to the base class type. This is a fundamental feature of class inheritance, and not one you can change.

Shadowing is when you create a property in a derived class that has the same name as one in the base class, this is sometimes used to replace the functionality of a property, but I have a feeling that if you are turning to this before answering the first issue, then you may need to look at the problem again.

Lastly I should emphasise that properties and variables are quite different; variables hold information, where as properties act as an access gateway for information, and do not actually retain information themselves. When a property is written like this:

Expand|Select|Wrap|Line Numbers
  1. public string Name { get; set; }
  2.  
C# converts this short-cut when the program is built, into something more like this:

Expand|Select|Wrap|Line Numbers
  1. private string m_Name;
  2.  
  3. public string Name 
  4. {
  5.   get { return m_Name; }
  6.   set { m_Name = value; } 
  7. }
  8.  
This is very relevant for understanding your question about shadowing, because understanding properties will show you weather you actually need to in the first place.

All the best!

Aimee Bailey.
Jun 14 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dinesh Garg | last post by:
Hi All, Following program does not compile because Class B does not provide " int foo(int) ". My Doubt here is why C++ hides the function in derived class with same name ;infact derived class...
10
by: William Stacey | last post by:
I know the following is not allowed, but shouldn't it be? sharedObject is part of Derived and should be able to be set in the constructor - no? tia public abstract class Base1 { protected...
9
by: Ken Varn | last post by:
Is there anyway to override a public virtual method or property so that it is private in my derived class? I tried using new on the property and making it private, but no luck. --...
1
by: Hans Bampel | last post by:
Hello group, i want to overwrite or manipulate a attribute of a property in a derived class. I use a attribute DBInfo via reflection on my properties to set the parameters in a SQL-statement...
6
by: Microsoft | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
7
by: Baski | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
3
by: martin | last post by:
Hi, If I have a base class, say called "MyBase" and a derived class called "Myderived" is it possible to get the name of the derived class from the base class fo example if I have a method in...
5
by: Joe | last post by:
Is there anyway to change the name or add a property to and existing class in .NET 1.1? For example if I have a property called Name and I want to change it to MyName. -Joe
3
by: Michael Chambers | last post by:
Hi there, Is there a clean way to change a property or method's attribute in a derived class without redefining the property/method itself. That is, redefining the property/method in the derived...
0
by: anileshlakhtakia | last post by:
Hi I have a class let say , Class A { public IList animal { get{}set{} } } Class B:A
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.