Link to home
Start Free TrialLog in
Avatar of cano63
cano63

asked on

C# function

Hi, I,m trying to create a function in a module and call it from any form of my program.

I just found that in C# 2003 there is no module. So can any one show me how i,m able to do this in c #.

I put a simple function in vb.net that is call from a form. how i convert this to c#

Also, i would like not use any class.

'this is my module '

Public function FullName as string (byval Fname, Lname as string)

FullName = Fname &" " & Lname

end function


'this is the code in the form that call the module that have the function

Load form
label1.text = FullName(Petter, henrick)
end sub

Open in new window

Avatar of silemone
silemone
Flag of United States of America image

SOLUTION
Avatar of silemone
silemone
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cano63
cano63

ASKER

What about the Module in c# ?
SOLUTION
Avatar of p_davis
p_davis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or in the class

this.Load += new System.EventHandler(this.FormName_Load);

void FormName_load(object sender, EventArgs e)
{

      label1.Text = FullName("Petter, "henrick);
 }
you don't have modules in c#
rather create a class and then create function inside it
rest it depends on your implementation you require it to b a static class or normal
in above case you can create a static class
you don't necessarily need a module...you could use a static class, a struct...there are many options...
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi

Please try this:

then from any form in your app call :

string displayName = MyStaticFunctions.FullName;



public static class MyStaticFunctions
{
    public static string FullName
    {
        get
        {
            return Fname + " " + Lname
        }
    }
}

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
again, with your specs of not wanting to use a class, you would use a struct...

see link:
http://msdn.microsoft.com/en-us/library/aa288471%28VS.71%29.aspx
Also, i would like not use any class.<----author's comment

again, with your specs of not wanting to use a class, you would use a struct...

see link:
http://msdn.microsoft.com/en-us/library/aa288471%28VS.71%29.aspx

the struct would include the method public string FullName that we all know how to create and there you have it...
Avatar of cano63

ASKER

All the Question were good and help me a lot in diferent ways