top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

c# function that returns string

0 votes
373 views

haw can i send string to function,do something with it and return to main in C#

posted Apr 28, 2017 by Leon Martinović

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

You can pass a string to function from main as given below:

I am passing string "MyName" to DisplayMessage function.The DisplayMessage function will return me another string which I will receive in displayName variable and can print it.

main()
{
  string name="MyName";
   string displayName=DisplayMessage(name);
Console.WriteLine({0},displayName);
}

public void DisplayMessage(string name)
{
 return "Leon";
}
answer May 3, 2017 by Shweta Singh
Similar Questions
0 votes

#region shell_sort

          //element for one step of sort
          int elm = 3;

          for (int i = 0; i != niz_brojeva.Length; i++)
          {
              int j = i + elm;

              if (j >= niz_brojeva.Length)
              { j = Convert.ToInt32(niz_brojeva.Length - 1); }

              while (i != j)
              {

                  if (niz_brojeva[i] > niz_brojeva[j])
                  {
                      int temp;
                      temp = niz_brojeva[i];
                      niz_brojeva[i] = niz_brojeva[j];
                      niz_brojeva[j] = temp;          
                  } j--; }
                 }
     #endregion
...