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

LVL 1
cano63Asked:
Who is Participating?
 
HainKurtSr. System AnalystCommented:
static class : http://msdn.microsoft.com/en-us/library/79b3xss3(VS.80).aspx

I did not know this ;) so the concept is similar to modules... I was thinking to create a public class with shared/static methods... but creating a static class with static functions in it is better...
0
 
silemoneCommented:
0
 
silemoneCommented:
Public string FullName(string Fname, string Lname)
{

return  Fname +" " + Lname;

}
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
cano63Author Commented:
What about the Module in c# ?
0
 
p_davisCommented:
public string FullName(string firstName, string lastName)
{
         return firstName + " " + lastName;
}


//double click on your form and form load event will be stubbed in for you if you are using Visual studio
//from there it is pretty much the same

//in the event
label1.Text = FullName("Petter, "henrick);




0
 
p_davisCommented:
or in the class

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

void FormName_load(object sender, EventArgs e)
{

      label1.Text = FullName("Petter, "henrick);
 }
0
 
Rakesh JaiminiCommented:
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
0
 
silemoneCommented:
you don't necessarily need a module...you could use a static class, a struct...there are many options...
0
 
zadeveloperCommented:
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

0
 
zadeveloperCommented:
sorry - let me complete the class

you need to set the values first:

so call

MyStaticFunctions.Fname = "first Name"
MyStaticFunctions.Lname = "Last Name"

and the reading
string name = MyStaticFunctions.FullName;


public static class MyStaticFunctions
{
    public static string Fname {get;set;}
    public static string Lname {get;set;}

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

Open in new window

0
 
silemoneCommented:
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
0
 
silemoneCommented:
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...
0
 
cano63Author Commented:
All the Question were good and help me a lot in diferent ways
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.