Creating Functions C#

  • Thread starter Thread starter Jl_G_0
  • Start date Start date
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.
 
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
 
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
 
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.
 
Back
Top