?
Solved

C# function

Posted on 2010-01-08
13
Medium Priority
?
201 Views
Last Modified: 2012-05-08
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

0
Comment
Question by:cano63
  • 5
  • 2
  • 2
  • +3
13 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 26213789
0
 
LVL 21

Assisted Solution

by:silemone
silemone earned 248 total points
ID: 26213815
Public string FullName(string Fname, string Lname)
{

return  Fname +" " + Lname;

}
0
 
LVL 1

Author Comment

by:cano63
ID: 26213829
What about the Module in c# ?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 22

Assisted Solution

by:p_davis
p_davis earned 248 total points
ID: 26213857
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
 
LVL 22

Expert Comment

by:p_davis
ID: 26213877
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
 
LVL 10

Expert Comment

by:Rakesh Jaimini
ID: 26213893
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
 
LVL 21

Expert Comment

by:silemone
ID: 26213910
you don't necessarily need a module...you could use a static class, a struct...there are many options...
0
 
LVL 61

Accepted Solution

by:
HainKurt earned 252 total points
ID: 26214028
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
 
LVL 13

Expert Comment

by:zadeveloper
ID: 26214434
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
 
LVL 13

Assisted Solution

by:zadeveloper
zadeveloper earned 252 total points
ID: 26214455
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
 
LVL 21

Expert Comment

by:silemone
ID: 26285435
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
 
LVL 21

Expert Comment

by:silemone
ID: 26285454
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
 
LVL 1

Author Closing Comment

by:cano63
ID: 31674764
All the Question were good and help me a lot in diferent ways
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Loops Section Overview
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question