473,473 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Static/new function new performing as expected

I have a problem with static functions and inheritance as demonstrated by the below samples

using System;
namespace ConsoleApplication1
{
class x
{
public static void Log()
{
Console.WriteLine("x.Log()");
}

public static void DoLog()
{
Log();
}
}

class y : x
{
public static new void Log()
{
Console.WriteLine("y.Log()");
}
}

class Class1
{
[STAThread]
static void Main(string[] args)
{
y.DoLog();
}
}
}

I was hoping that this program would output "y.log", since I call the "y" inherited static method
but instead it output "x.log", because the DoLog() method is binding to the "local" static

Can I do something to the code in my "x" class to make it call y - while still using static functions?
I do not want to override all the "DoLog"-like functions in my x class.
I know that this would work for non-static functions e.g.:

using System;
namespace ConsoleApplication1
{
class x
{
public virtual void Log()
{
Console.WriteLine("x.Log()");
}

public void DoLog()
{
Log();
}
}

class y : x
{
public override void Log()
{
Console.WriteLine("y.Log()");
}
}

class Class1
{
[STAThread]
static void Main(string[] args)
{
new y().DoLog();
}
}
}

Rgds,
Thomas Fritzen
Nov 17 '05 #1
1 1224
In article <O8**************@TK2MSFTNGP14.phx.gbl>, tf*@mondosoft.NO-
SPAM.com says...
I have a problem with static functions and inheritance as demonstrated by the below samples

<snip>


Static members are not inherited. Static members are members of the
type itself, not an instance of the type.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 17 '05 #2

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

Similar topics

3
by: rashkatsa | last post by:
Hi all, do you know why python development team decided to forbid polymorphism for static methods ? As you can do it in another languages (Java,...) it could be very handy if you can create...
0
by: Jeffrey B. Holtz | last post by:
Has anyone used the multimedia timere timeSetEvent in C#? I'm trying to use it to get a 1ms accurate timer. All the other implementations are far to inaccurate in their resolution. 1ms Timer =...
3
by: Mauzi | last post by:
hi, this may sound odd and noob like, but what is the 'big' difference between static and non-static funcitons ? is there any performace differnce? what is the best way to use them ? thnx ...
14
by: knocte | last post by:
Hello. I have a problem with C# language. I want to define an algorithm on a static function inside an abstract class. This function calls a static variable inside the same class. Then I want to...
6
by: Bill Rubin | last post by:
The following code snippet shows that VC++ 7.1 correctly compiles a static member function invocation from an Unrelated class, since this static member function is public. I expected to compile the...
13
by: jamihuq | last post by:
Can someone please tell me what I am doing wrong. I wrote this static inline function to test another function and I am getting errors which make no sense to me. thanks Jami /* test2.h */ ...
4
by: Josefo | last post by:
Hello, is someone so kind to tell me why I am getting the following errors ? vector_static_function.c:20: error: expected constructor, destructor, or type conversion before '.' token...
3
by: Richard K Miller | last post by:
Here's an OOP question that perplexes me. It seems PHP doesn't treat static variables correctly in child classes. <?php class ABC { public $regular_variable = "Regular variable in ABC\n";...
8
by: aarklon | last post by:
Hi all, see:- http://linuxgazette.net/issue51/pramode.html
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.