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

new class modifier and tested class

Documents say that "new" class modifier is only used with nested classes.
"new" indicates that the class hides an inherited member of the same name."

public class MyDerivedC : MyBaseC
{
new public void Invoke() {}
}

The only thing I don't understand in the above statement and example is that
it says that "new" only used with nested classes. However the example isn't
nested class; it's an inheritance. An example of nested class should be
something like:

class NestedClass
{
class MyClass
{
public string name;
public int id;

public MyClass ()
{
}

public MyClass (int id, string name)
{
this.id = id;
this.name = name;
}
}
....
}

Am I misunderstanding "nested class" concept in C#? Would someone share his
light on this?

Many thanks!

Nov 15 '05 #1
3 1382

"fh1996" <fh****@yahoo.com> wrote in message
news:u9**************@TK2MSFTNGP09.phx.gbl...
Documents say that "new" class modifier is only used with nested classes.
"new" indicates that the class hides an inherited member of the same name."
public class MyDerivedC : MyBaseC
{
new public void Invoke() {}
}
In this case, new is on a method, not a class. The new modifier on a method
shadows the MyBaseC.Invoke method, be it inheritable or not, with a new
method named MyDerivedC.Invoke.

The only thing I don't understand in the above statement and example is that it says that "new" only used with nested classes. However the example isn't nested class; it's an inheritance. An example of nested class should be
something like:

class NestedClass
{
class MyClass
{
public string name;
public int id;

public MyClass ()
{
}

public MyClass (int id, string name)
{
this.id = id;
this.name = name;
}
}
...
}
You would need new in this case, I think, if your class was inheriting from
another class that already had class MyClass nested within it.

Am I misunderstanding "nested class" concept in C#? Would someone share his light on this?

Many thanks!


Nov 15 '05 #2
fh1996 <fh****@yahoo.com> wrote:
Documents say that "new" class modifier is only used with nested classes.


Which documents say that? It's not true.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
Don't confuse "class modifier" with "method modifier." They're two different
things. You're using new as a method modifier and the rules are different.

Pete

"fh1996" <fh****@yahoo.com> wrote in message
news:u9**************@TK2MSFTNGP09.phx.gbl...
Documents say that "new" class modifier is only used with nested classes.
"new" indicates that the class hides an inherited member of the same name."
public class MyDerivedC : MyBaseC
{
new public void Invoke() {}
}

The only thing I don't understand in the above statement and example is that it says that "new" only used with nested classes. However the example isn't nested class; it's an inheritance. An example of nested class should be
something like:

class NestedClass
{
class MyClass
{
public string name;
public int id;

public MyClass ()
{
}

public MyClass (int id, string name)
{
this.id = id;
this.name = name;
}
}
...
}

Am I misunderstanding "nested class" concept in C#? Would someone share his light on this?

Many thanks!


Nov 15 '05 #4

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

Similar topics

2
by: Dan Disney | last post by:
I have read conflicting information on the access scope of VB.Net class declarations when no access modifier is specified. MSDN library documentation states "Classes that do not specify an access...
18
by: Jason Heyes | last post by:
Is this class evidence of poor design? class Rectangle { double width, height; public: double get_width() const { return width; } double get_height() const { return height; } void...
4
by: Gerben van Loon | last post by:
Hello, I'm quite new to Csharp and like to know how I can call a function from an upper class. Following example might explain my problem a bit better: public class MyClass { public void...
2
by: SamIAm | last post by:
Hi I am looking at implementing a Facade architecture in my system. i.e MyBusinessFacdeSystem and multiple MyBusinessObjects I want the MyBusinssObject class to only be created by the...
2
by: Dan Cimpoiesu | last post by:
Hello What does mean when a protected modifier is apllied to a class. I want to inherit a protected class defined in another class, I saw that the microsoft programmers achieved that. But I...
19
by: hamil | last post by:
I have a form with one button, Button1, and a Textbox, Textbox1 I have a class, class1 as follows. Public Class Class1 Public DeForm As Object Sub doit() DeForm.Textbox1.text = "It works"...
10
by: =?iso-8859-2?B?SmFuIFJpbmdvuQ==?= | last post by:
Hello everybody, this is my first post to a newsgroup at all. I would like to get some feedback on one proposal I am thinking about: --- begin of proposal --- Proposal to add...
1
by: =?Utf-8?B?Z3JpZmY=?= | last post by:
I've run into an interesting set of problems. I need to override the HttpWebRequest that is used by the autogenerated class from add a web reference. I'm using C# in VS2005. I thought using a...
3
by: Matt | last post by:
Hi everyone, can someone point out the difference between defining a class with the public access modifier and just leaving it as it is (default in vs.net "class") I think that the default...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.