473,322 Members | 1,714 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,322 software developers and data experts.

Several C# questions

1) How come const cannot be declared with static? Does const already
mean static/implemented as static in C#?

2) How do I make a public non-overridable function/property in the super
class private in the subclass? I want to completely hide that public
function without providing a subclass alternate, so the "new" accessor
doesn't really fit here...

Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #1
3 1101
<Kaki <--NO-->> wrote:
1) How come const cannot be declared with static? Does const already
mean static/implemented as static in C#?
Yes.
2) How do I make a public non-overridable function/property in the super
class private in the subclass? I want to completely hide that public
function without providing a subclass alternate, so the "new" accessor
doesn't really fit here...


You can't, as that would violate the Liskov Substitutability Principle.

Think of it this way: people would still be able to do

Base b = new DerivedClass();
b.MethodRemovedInDerived();

so it wouldn't help you much anyway.

If you don't want your derived class to do everything the base class
can, consider composition instead of inheritance.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
About this part:

Base b = new DerivedClass();
b.MethodRemovedInDerived();

How come it's not consistent with property? Say there's a property with
get&set in the base class, the language allows the derived class to hide
it with only get/set, but doesn't prevent people from trying:

Base b = new Derived();
b.PropertyReadOnlyInDerived = "something";

Any ideas?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #3
<Kaki <--NO-->> wrote:
About this part:

Base b = new DerivedClass();
b.MethodRemovedInDerived();

How come it's not consistent with property? Say there's a property with
get&set in the base class, the language allows the derived class to hide
it with only get/set, but doesn't prevent people from trying:

Base b = new Derived();
b.PropertyReadOnlyInDerived = "something";

Any ideas?


I don't see that that's inconsistent. Again, you're making the compiler
only consider it as if it were the base class, not the derived class.
Why is this inconsistent?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: michela rossi | last post by:
Hi, Don't know if anyone can help me. I've got the following questions: 1. Does anyone know of anywhere that offers shared webspace which has support for Java/JSP? Ideally running Tomcat? 2. ...
1
by: Torsten Mohr | last post by:
Hi, i'd like to write an extension module and use PyArg_ParseTuple in that to parse the parameters. I have several questions related to this that i did not find in the documentation: 1....
0
by: Victor Porton | last post by:
Suppose I create several RSS channels: http://example.com/company-news.rdf http://example.com/new-products.rdf http://example.com/product-updates.rdf etc. They are interrelated: for example,...
5
by: NotGiven | last post by:
I have a form with several questions. Within each question there are several checkboxes. I need to ensure that the user checks at least one checkbox. They can check more but must check at least...
1
by: Ayende Rahien | last post by:
I'm storing my data inside an XML file, the data is divided into several niches. I expect two things to happen during normal use of the application: A> Number of niches to grow. B> Amount of...
0
by: Chad A. Beckner | last post by:
I am starting to work on implementing ASP.NET (using VS.NET Dev 2003) into our current ASP 3.0 intranet setup. We have several (say 15 - 20) "applications" that are run within our intranet, which...
2
by: Tiago Miguel Silva | last post by:
Hi there to all. I am a .NET Crystal newbie and I hope that you don’t pick me up much :) with the following questions: 1) It’s possible to access the report model to alter the rendered...
7
by: Byron | last post by:
I have several user controls that have a few methods in common, such LoadFromForm() which populates an object from controls on the form. I want to call that method from the form in which the...
9
by: eitan | last post by:
Hello, I am using Microsoft Visual Studio 2003 .NET. I have several question, please. 1) I have a connection to the database, which I create it at login, by application("conMain") (I have...
1
by: Joe | last post by:
Dear all, I have many questions, please help! 1.) If i use the backup/restore function in the IIS, does the backup includes only the register and settings of web sites in the IIS only, or does it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.