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...
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...
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...
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...
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...
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...
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 ...
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 ...
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...
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...
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...
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?
...
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
...
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...
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
*...
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...
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...
Can anybody tell what is the module/method used to get current time ???
...
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?
...
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...