Click here to Skip to main content
16,005,162 members
Home / Discussions / C#
   

C#

 
GeneralBeginRead Method Pin
mikeyhardingboyo8-Jan-05 12:48
mikeyhardingboyo8-Jan-05 12:48 
GeneralRe: BeginRead Method Pin
kiranprabhu9-Jan-05 1:42
kiranprabhu9-Jan-05 1:42 
GeneralWIZARD FOR CONSTRUCTOR?! Pin
...---...8-Jan-05 12:07
...---...8-Jan-05 12:07 
GeneralRe: WIZARD FOR CONSTRUCTOR?! Pin
Matt Gerrans9-Jan-05 9:39
Matt Gerrans9-Jan-05 9:39 
GeneralWIZARD FOR CONSTRUCTOR?! Pin
...---...8-Jan-05 12:07
...---...8-Jan-05 12:07 
GeneralRe: WIZARD FOR CONSTRUCTOR?! Pin
leppie8-Jan-05 20:35
leppie8-Jan-05 20:35 
GeneralRe: WIZARD FOR CONSTRUCTOR?! Pin
Christian Graus8-Jan-05 22:24
protectorChristian Graus8-Jan-05 22:24 
Generalthe use of keyword new, when overriding methods Pin
thallish8-Jan-05 9:52
thallish8-Jan-05 9:52 
Hey

I'm doing a little C# exercise and it involves overriding an inherited method

Here is my code

using System;<br />
<br />
namespace BookOverride<br />
{<br />
	class Book<br />
	{<br />
		public string Title()<br />
		{<br />
			return "Damn Good Book";<br />
		}<br />
		public string Rating()<br />
		{<br />
			return "5 Stars";<br />
		}<br />
	}<br />
	<br />
	class OtherBook : Book<br />
	{<br />
		public string Title()<br />
		{<br />
			return "Some Other Damn Good Book";<br />
		}<br />
	}<br />
<br />
	class Class1<br />
	{<br />
		static void Main(string[] args)<br />
		{<br />
			Book bc = new Book();<br />
			Console.WriteLine(bc.Title());<br />
			Console.WriteLine(bc.Rating());<br />
			<br />
			OtherBook ob = new OtherBook();<br />
			Console.WriteLine(ob.Title());<br />
			Console.WriteLine(ob.Rating());<br />
		}<br />
	}<br />
	<br />
}


Now the funny thing is that my VS .NET tells me that new is required when creating the method in class OtherBook, but the whole thing works without it? I do get a warning though

warning CS0108: The keyword new is required on 'Polymorphism.B.Foo()' because it hides inherited member 'Polymorphism.A.Foo()'

Anybody knows why it issues a warning instead of an error?

I am gonna use the new keyword from now on. It's nice to see which methods that get overridden, but does it have a valid purpose other than that?

/thallish


---Sometimes it's the smallest of things that make the biggest of systems crash.... Hey get away from that switch!!!
GeneralRe: the use of keyword new, when overriding methods Pin
thallish8-Jan-05 10:17
thallish8-Jan-05 10:17 
GeneralRe: the use of keyword new, when overriding methods Pin
DavidNohejl8-Jan-05 10:27
DavidNohejl8-Jan-05 10:27 
GeneralRe: the use of keyword new, when overriding methods Pin
DavidNohejl8-Jan-05 10:24
DavidNohejl8-Jan-05 10:24 
GeneralRe: the use of keyword new, when overriding methods Pin
Adam Goossens9-Jan-05 23:00
Adam Goossens9-Jan-05 23:00 
GeneralRe: the use of keyword new, when overriding methods Pin
turbochimp10-Jan-05 2:39
turbochimp10-Jan-05 2:39 
GeneralMultiple Instances Pin
TyronX8-Jan-05 7:46
TyronX8-Jan-05 7:46 
GeneralRe: Multiple Instances Pin
Matt Gerrans8-Jan-05 8:06
Matt Gerrans8-Jan-05 8:06 
GeneralRe: Multiple Instances Pin
TyronX8-Jan-05 11:22
TyronX8-Jan-05 11:22 
GeneralRe: Multiple Instances Pin
TyronX8-Jan-05 11:41
TyronX8-Jan-05 11:41 
GeneralRe: Multiple Instances Pin
Matt Gerrans9-Jan-05 6:25
Matt Gerrans9-Jan-05 6:25 
GeneralRe: Multiple Instances Pin
Matt Gerrans9-Jan-05 6:17
Matt Gerrans9-Jan-05 6:17 
GeneralRe: Multiple Instances Pin
TyronX10-Jan-05 8:55
TyronX10-Jan-05 8:55 
GeneralRe: Multiple Instances Pin
Matt Gerrans10-Jan-05 19:10
Matt Gerrans10-Jan-05 19:10 
GeneralRe: Multiple Instances Pin
Allan Eagle8-Jan-05 15:02
Allan Eagle8-Jan-05 15:02 
GeneralRe: Multiple Instances Pin
TyronX9-Jan-05 2:29
TyronX9-Jan-05 2:29 
GeneralRe: Multiple Instances Pin
TyronX10-Jan-05 9:32
TyronX10-Jan-05 9:32 
GeneralKeypress Pin
The underdog8-Jan-05 6:14
The underdog8-Jan-05 6:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.