method-overloading

Overloading methods in C#

Is there a way to simplify the process of adding an overloaded method in C# using VS2005? In VB6, I would have just added an Optional parameter the function, but in C# do I have to have to type out a whole new method with this new parameter? ...

Different behaviour of method overloading in C#

Hi All, I was going through C# Brainteasers (http://www.yoda.arachsys.com/csharp/teasers.html) and came across one question: what should be the output of this code? class Base { public virtual void Foo(int x) { Console.WriteLine ("Base.Foo(int)"); } } class Derived : Base { public override void Foo(int x) { ...

Method overloading in groovy

I am trying to take advantage of the convenience of groovy's scripting syntax to assign properties, but having trouble with a specific case. I must be missing something simple here. I define class A, B, C as so: class A { A() { println "Constructed class A!" } } class B { B() { println "Constructed class...

Best practices regarding equals: to overload or not to overload?

Consider the following snippet: import java.util.*; public class EqualsOverload { public static void main(String[] args) { class Thing { final int x; Thing(int x) { this.x = x; } public int hashCode() { return x; } public boolean equals(Thing other) { return this.x ==...

WCF:recommended naming conventions for same method with different signatures?

Hi there, been creating a few wcf methods and i have a mehtod called IsValidLogin ... there various versions, 1 takes 2 strings, 1 takes an object etc. Of course in WCF you can't overload methods can anyone suggest the best way to name these methods.. I was thinking of IsValidLogin1, IsValidLogin2?? But i am open to any suggestions ...

How to proxy calls to the instance of an object

Edit: Changed question title from "Does C# allow method overloading, PHP style (__call)?" - figured out it doesn't have much to do with actual question. Also edited question text. What I want to accomplish is to proxy calls to a an instance of an object methods, so I could log calls to any of its methods. Right now, I have code similar...

How to prevent a method from overloading in Java?

Overriding a method can be prevented by using the keyword final, likewise how to prevent overloading? ...

SqlParameter contructor compiler overload choice

When creating a SqlParameter (.NET3.5) or OdbcParameter I often use the SqlParameter(string parameterName, Object value) constructor overload to set the value in one statement. When I tried passing a literal 0 as the value paramter I was initially caught by the C# compiler choosing the (string, OdbcType) overload instead of (string, Obj...

How is method group overload resolution different to method call overload resolution?

The following code doesn't compile (error CS0123: No overload for 'System.Convert.ToString(object)' matches delegate 'System.Converter<T,string>'): class A<T> { void Method(T obj) { Converter<T, string> toString = Convert.ToString; // this doesn't work either (on .NET 4): Converter<object, string> toString2 ...

Why is the return type not considered when differentiating methods?

Possible Duplicate: Java - why no return type based method overloading? The compiler does not consider return type when differentiating methods, so you cannot declare two methods with the same signature even if they have a different return type. Java Tutorial Why is this? ...

Why does String.valueOf(null) throw a NullPointerException?

Hi, according to the documentation, the method String.valueOf(Object obj) returns: if the argument is null, then a string equal to "null"; otherwise, the value of obj.toString() is returned. But how come when I try do this: System.out.println("String.valueOf(null) = " + String.valueOf(null)); it throws NPE instead? (try it your...

Refactoring some code with 'instanceof' to overloaded method solution in Java

I have this piece of code from GWT in Action: public void processOperator(final AbstractOperator op) { System.out.println("Wordt deze ooit aangeroepen?"); if (op instanceof BinaryOperator) { if ((data.getLastOperator() == null) || (data.isLastOpEquals())) { data.setBuffer(Double.parseDouble(da...

How can I pass an instance of a subtype of a class to a corresponding overloaded method?

I'm refactoring an existing state machine that heavily used case statements and emums. I've broken it down to Events and eventhandler objects, each corresponding to a state machine. The eventHandlers return new Events to propagate through the state machine. So, my code looks something like this: public class Event { //common fields...

Python: **kargs instead of overloading?

Hi, I have a conceptual Python design dilemma. Say I have a City class, which represents a city in the database. The City object can be initialized in two ways: An integer (actually, an ID of an existing city in a database) A list of properties (name, country, population, ...), which will generate a new city in the database, and re...

Overloading a Native PHP Function to Encypt Data for HIPAA Compliance

Background Information: I'm part of a team of developers that runs a web application that stores and retrieves HIPAA (medical) data. Recently, the HIPAA guidelines were updated to include a policy that requires that all identifying client information be encrypted when it is "at rest" (stored in the database and not being accessed). The...

C# in VS2005: can you overload the .ToString() method of a property?

C# in VS2005: can you overload the .ToString() method of a property? ...

Scala double definition (2 methods have the same type erasure)

Hi I wrote this in scala and it won't compile: class TestDoubleDef{ def foo(p:List[String]) = {} def foo(p:List[Int]) = {} } the compiler notify: [error] double definition: [error] method foo:(List[String])Unit and [error] method foo:(List[Int])Unit at line 120 [error] have same type after erasure: (List)Unit I know JVM has no...

method overloading vs optional parameter in C# 4.0

which one is better? at a glance optional parameter seems better (less code, less XML documentation, etc), but why do most MSDN library classes use overloading instead of optional parameters? Is there any special thing you have to take note when you choose to use optional parameter (or overloading)? ...

C++: inheriting overloaded non-virtual method and virtual method both with the same name causes problem

Hi all, I am trying to inherit two equally named methods with different parameter lists to a derived class. One of them is virtual and overridden in the derived class, the other one is non-virtual. Doing so, i get a compile error while trying to access the non-virtual method of the base class from an derived class object. Here is the ...

Method resolution in Comparer

Hi all, consider the following basic class layout: public class Base : IComparable<Base> { public int CompareTo(Base other) { //Do comparison } } public class Derived : Base, IComparable<Derived> { public int CompareTo(Derived other) { //Do comparison } } public class BaseComparer : IComparer<Base> { public in...