473,386 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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!
Jan 10 '08 #1
1 1067
Snaggy wrote:
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.
Jan 10 '08 #2

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

Similar topics

10
by: BadOmen | last post by:
I have made an array in a function in a Class now I need to get to that Array from an other function in an other Class, How do I do that? The Array has no fixed size as it is dependent on how...
2
by: Daniel Schüle | last post by:
Hi all i am new to python but not to programming in general i tryed the code below i would write in C++ in particular the nested classes and creation of objects in constr my questions are...
3
by: Kostas Kousinovalis | last post by:
Hello Is it so difficult to make a databound form or am I somewhere wrong? First I create a SQL DataAdapter with a connection to Northwid Products VB creates a SQLConnection1 Then I'm...
3
by: Jeff | last post by:
for your info - I'm a newbe. Code is at the bottom. Access dbase (each form ca. 10 KB) if my explanations are not enough (probably they aren't). -- access 97 -...
5
by: ken | last post by:
Hi, I have two questions the first is: in the example below how can I call an event from within a statement, such as replace Stop1 with cmdStop1 which is a button on my form? My second question...
19
by: AMP | last post by:
I have a simple question. If i have a button on form1 that creates : Form2 newform = new Form2(); newform.Show(); As I click the button a new form shows,but acording to my code each one has...
13
by: Eric_Dexter | last post by:
All I am after realy is to change this reline = re.line.split('instr', '/d$') into something that grabs any line with instr in it take all the numbers and then grab any comment that may or may...
3
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
When a Microsoft help topic says to use this code, where woudl you place it? Sorry, I know its a lame questions. I am a beginner. public class DataGridViewRow : DataGridViewBand
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.