Why can't I ... a few newbe questions

S

Snaggy

1. Why arent't default parameters accepted? Why do I have to use
polymorphism everywhere? This makes my code redundant. Example:

public string showStuff (string whatToShow, int limit = 0){...}

instead of:

public string showStuff(string whatToShow){...}
public string showStuff(string whatToShow, int limit){...}

how do you approach the matter? I'm calling the non overloaded
function in the overloaded one ... isn't there a simpler way?

2. Can I create a function with an indefinite number of parameters?
Example:

public myFunction(string param1, int param2, ){...}
myFunction("hey", 3, "additional stuff")

I guess not..


lots of other questions but right now I gotta go... hope I'll get to
know C# since right now it's annoying how difficult it is for me to
do the same things I did in PHP or Ruby with no effort..


bye!
 
C

Chris Shepherd

Snaggy said:
1. Why arent't default parameters accepted? Why do I have to use
polymorphism everywhere? This makes my code redundant. Example:

public string showStuff (string whatToShow, int limit = 0){...}

instead of:

public string showStuff(string whatToShow){...}
public string showStuff(string whatToShow, int limit){...}

how do you approach the matter? I'm calling the non overloaded
function in the overloaded one ... isn't there a simpler way?

That is the simpler way.
2. Can I create a function with an indefinite number of parameters?
Example:

public myFunction(string param1, int param2, ){...}
myFunction("hey", 3, "additional stuff")

I guess not..

Yes, you can.

public myFunction(params object[] paramList) {...}

myFunction("stuff", 123, 456.00, DateTime.Now, true, new Exception("Oops!"));


Chris.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top