methods

C# equivalent of C++ mem_fun?

I'd like to do something like the following in C#: class Container { //... public void ForEach(Action method) { foreach (MyClass myObj in sequence) myObj.method(); } } //... containerObj.ForEach(MyClass.Method); In C++ I would use something like std::mem_fun. How would I do it in C...

Persistent HTTP GET variables in PHP

Let's say I have some code like this if(isset($_GET['foo'])) //do something if(isset($_GET['bar'])) //do something else If a user is at example.com/?foo=abc and clicks on a link to set bar=xyz, I want to easily take them to example.com/?foo=abc&bar=xyz, rather than example.com/?bar=xyz. I can think of a few very messy ways to...

What single characteristic is most important for a good routine?

Routines, procedures, methods - whatever you call them, they are important building blocks for us developers. What single characteristic would you rate as the most important one? (By providing one characteristic per answer, it is possible to vote for them individually. I.e. the purpose of this question is not to decide single out one ch...

Question about object.method in JavaScript

This is a follow-up question to this one. Take a look at these two examples: var number1 = new Number(3.123); number1 = number1.toFixed(2); alert(number1); var number2 = 3.123; number2 = number2.toFixed(2); alert(number2); I realize they both end up with the same value, but is it correct thinking to refer to a method of a primitiv...

Cool way to call methods on multiple objects in Ruby?

A long time ago I saw this trick in Ruby. Instead of doing (for example) if array1.empty? and array2.empty? and array3.empty? You could call all of the objects at once and append the operation at the end, kind of like if %w(array1 array2 array3).each { |a| a.empty? } But I think it was simpler than that... or, it could be that. I r...

Method overloading behaviour

I have the following code sample : public class Base { public virtual void MyMethod(int param) { Console.WriteLine("Base:MyMethod - Int {0}", param); } } public class Derived1 : Base { public override void MyMethod(int param) { Console.WriteLine("Derived1:MyMethod - Int {0}", param); } public...

C++ : friend AND inline method, what's the point ?

Hello, I see in a header that I didn't write myself the following : class MonitorObjectString: public MonitorObject { // some other declarations friend inline bool operator==(MonitorObjectString& lhs, MonitorObjectString& rhs) { return(lhs.fVal==rhs.fVal); } I can't understand why this method is declared as friend. I thought ...

Using Objects across methods

Edit again: I think I get it now. All I need to do then is use the current class colon the class I want to be able to access? Person : Student, or person : teacher Is that correct? Thank everyone for the help, I really appreciate it. This will help me learn what is OO and what is not. I really appreciate that. I'm currently ...

Using return statements to great effect!

When I am making methods with return values, I usually try and set things up so that there is never a case when the method is called in such a way that it would have to return some default value. When I started I would often write methods that did something, and would either return what they did or, if they failed to do anything, would r...

Passing superclass as parameter to method expecting sub class

Hello, I have an object tree that looks something like Ball / \ LegalBall IllegalBall And I have 2 methods: class o { AddBall(LegalBall l) AddBall(IllegalBall i) } in another class I'd like to do the following: o.AddBall(myBall); where myBall is of type Ball. And get it to call the correct method de...

Where should I put my first method

Hello. I've a need to add method that will calculate a weighted sum of worker salary and his superior salary. I would like something like this: class CompanyFinanse { public decimal WeightedSumOfWorkerSalaryAndSuperior(Worker WorkerA, Worker Superior) { return WorkerA.Salary + Superior.Salary * 2; } } Is t...

Is there a better way to test for an integer in C# than Double.TryParse?

Double.TryParse returns a value, and I don't need a value. I need to be able to tell if a string is numeric and just return a bool. is there a way to do this? ...

ASCX controls ASP.NET - Cannot find Visible method

In a particular page i have a ascx control which contains a table. Now I want to set this control visible/invisible but the visible method is not detected by the intellisense. The only methods are 1)Equals and 2) ReferenceEquals Main Page <VPM:VotingPolls Runat="server"></VPM:VotingPolls> Thanks ...

OO style parameters vs type parameters

Say you have these two methods: Number 1: void AddPerson(Person person) { // Validate person if(person.Name != null && IsValidDate(person.BirthDate) DB.AddPersonToDatabase(person); } Number 2: void AddPerson(string name, DateTime birthDate) { Person p = new Person(name, birthDate); DB.AddPersonToDatabase(person); } Wh...

Why is accessing a static method from a non-static method bad?

Netbeans tells me it's bad to access a static method from a non static method. Why is this bad? "Accessing static method getInstance" is the warning: import java.util.Calendar; public class Clock { // Instance fields private Calendar time; /** * Constructor. Starts the clock at the current operating system time *...

C# - Do method names get compiled into the EXE?

Do class, method and variable names get included in the MSIL after compiling a Windows App project into an EXE? For obfuscation - less names, harder to reverse engineer. And for performance - shorter names, faster access. e.g. So if methods ARE called via name: Keep names short, better performance for named-lookup. Keep names crypt...

How Do I Pass A Method Reference to A Different Method in C#

I would like to pass a reference of a method into another method and store it as a variable. Later, I would like to use this reference to define an event handler. When making an event handler, a method reference is passed like: myButton.Click += new RoutedEventHandler(myButton_Click); And if you look at the constructor for "RoutedEv...

How to get current time in Python

Can anybody tell what is the module/method used to get current time ??? ...

How to refer to Method objects in Java?

Or, in other words, what is wrong with something like - new Method[] {Vector.add(), Vector.remove()} Eclipse keeps telling me that I need arguments. But I obviously don't want to call the methods, I just want to use them as objects! What to do? ...

Calling methods of "parent" component in Java

I have the following situation I think would be best to show in sample program code. I have a Java class that extends JPanel. In this class are two objects which are two more JPanels. In one of the JPanel objects is a JTable object. I added a listener to this JTable that detects a double click. When it detects a double click, I want...