Creating Functions C#

J

Jl_G_0

Hey all, got one question about creation of functions. I have a
function that receives a sql string and a datagrid to populate.

void populate(DataGrid grid, string sql){
......
}

Lets say I want to upgrade this function, so it can receive a
DataGrid OR a GridView, just like several C# functions can receive a
lot of different types (Convert.ToString() receives 36 I guess) how
could I do it ?? or maybe what should I search for ??

Thanks.
 
O

OZI

a Function should have a return value and you have void, method is the
name.

void populate(DataGrid grid, string sql){

private void populate(DataGrid grid, string sql){}
private void populate(GridView grdvw, string sql){}

just overload.

OZI
 
R

Roland Dick

Hi,

Jl_G_0 said:
void populate(DataGrid grid, string sql){
Lets say I want to upgrade this function, so it can receive a
DataGrid OR a GridView, just like several C# functions can receive a

You can create a new function with the same name and other parameters, e.g.:
void populate(GridView grid, string sql)

The only thing to keep in mind is that the signature (= name of function
and number, order and type of parameters) must be unique.

Hope this helps,

Roland
 
J

Jl_G_0

thx everybody. Yeah, its really not void, sorry... its INT populate(),
so it returns non-zero if it fails.
And I thought I could do this saving some lines of code, but looks
like I have to copy the same function over and over... well, it works
fine. thx again.
 

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

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top