Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# function return

// To create a function with a return value, note the variable
// type in front of the function name and add a return of the
// same type at the end.
static string lastFirst(string firstName, string lastName)
{
	string separator = ", ";
	string result = lastName + separator + firstName;
	return result;
}
Comment

how to return a value in c#

   void Start()
    {
        Debug.Log(Message()/*calling the function with its name*/);
    }

    string Message()/*you can make values to functions with () and {}*/
    {
        string message = "Hello world";
        return message;//this says which value will be returned
    }
Comment

c# how to return a function

public void DoSomething()                          // Action
public void DoSomething(int number)                // Action<int>
public void DoSomething(int number, string text)   // Action<int, string>

public int DoSomething()                           // Func<int>
public int DoSomething(float number)               // Func<float, int>
public int DoSomething(float number, string text)  // Func<float, string, int>
Comment

C# Return Statement

int cubedNumber = cube(5);
Console.WriteLine(cubedNumber);



Console.ReadLine();


static int cube(int num)
{
    int result = num * num * num;
    return result;
}
Comment

C# return values

public async Task DeleteSchoolTask(int schoolNumber, int taskDetailId)
        {  
            var result = await GetTaskTypeAndId(taskDetailId);
            int taskId = result.Item1;
            string taskType = result.Item2;

            // step 1: delete attachment physically from server
            var fileService = new FileService(Logger, CurrentUser);
            var relativeFilePath = $"{schoolNumber}{Consts.RM_SCHOOL}{taskDetailId}";
            fileService.DeleteAttachmentFolderFromServer(Consts.CONFIG_SMP_UPLOADFILE_ROOTPATH, relativeFilePath);

            // step 2: delete records from database
            await _routineMaintenanceRepo.Value.DeleteSchoolTask(taskDetailId);
        }

        public async Task<(int, string)> GetTaskTypeAndId(int taskDetailId)
        {
            var detailRecord = await _routineMaintenanceRepo.Value.GetDetailRecord(taskDetailId);

            int taskId = 0;
            string taskType = "";

            switch (detailRecord.TaskType)
            {
                case 1:
                    taskId = (int)detailRecord.RoutineMaintenanceTaskId;
                    taskType = Consts.RM_DEFAULT;
                    break;
                case 2:
                    taskId = (int)detailRecord.RoutineMaintenanceTaskDuplicateId;
                    taskType = Consts.RM_DUPLICATE;
                    break;
                case 3:
                    taskId = (int)detailRecord.RoutineMaintenanceTaskSchoolId;
                    taskType = Consts.RM_SCHOOL;
                    break;
                default:
                    break;
            }
            return (taskId, taskType);
        }
Comment

PREVIOUS NEXT
Code Example
Csharp :: Get single listView SelectedItem 
Csharp :: #movement speed c 
Csharp :: ASP.NET C# Catch all exceptions in a class 
Csharp :: close an open form when you open it again c# 
Csharp :: asp net mvc convert ienumerable to selectlistitem 
Csharp :: data types of document in asp dot net frame work 
Csharp :: // Force WPF to render UI changes immediately with this magic line of code... 
Csharp :: Unity how get Attributes of a gameObject 
Csharp :: c# string interpolation float format 
Csharp :: C# EDSDK control lens 
Csharp :: 2d collision handling jump table 
Csharp :: c# name script 
Csharp :: Microsoft.ACE.OLEDB.12.0 c# excel first sheet 
Csharp :: display array value sin C# 
Csharp :: c# show existing form 
Csharp :: C# Relational Operators 
Csharp :: what is the difference between rotation rotation axis and equator 
Csharp :: delete content from file c# 
Csharp :: == vs equals c# 
Csharp :: inline c# custom operator implicit 
Csharp :: c# how to return 2 strings 
Csharp :: Xamarin Forms iOS Picker done 
Csharp :: Known Folders C# 
Csharp :: same click method lots of buttons c# 
Csharp :: Modify middleware response c# .net 
Csharp :: cmd.executenonquery() error in c# 
Csharp :: how to unfocus a richtextbox windows forms 
Csharp :: ########## 
Csharp :: c# decimal literal 
Csharp :: c# object list contains object returns incorrect boolean 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =