Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

Creating Functions C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jl_G_0 - 13 Sep 2007 16:05 GMT
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.
OZI - 13 Sep 2007 16:15 GMT
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

> Hey all, got one question about creation of functions. I have a
> function that receives a sql string and a datagrid to populate.
[quoted text clipped - 9 lines]
>
> Thanks.
Roland Dick - 13 Sep 2007 16:22 GMT
Hi,

Jl_G_0 schrieb:
> 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
Jl_G_0 - 13 Sep 2007 16:31 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.