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# get the return value of a func

Func<int> function;
int returnValue;

function = () => 0;
returnValue = function();
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 :: c# how to check the minimum and maximum of numbers 
Csharp :: how to set the server url in dotnet core 
Csharp :: dbset 
Csharp :: how to add arrays in c# 
Csharp :: csv to xml using xmldocument c# 
Csharp :: c# extension 
Csharp :: DateTime restrictions 
Csharp :: array to object c# 
Csharp :: unity animation length 
Csharp :: or operator in c# 
Csharp :: c# how to return a function 
Csharp :: bezier_curve 
Csharp :: how to use date range picker in asp.net C# 
Csharp :: can object change color when collided with particles unity 
Csharp :: How do I call a string inside a different class 
Csharp :: rename join ta le in many to many 
Csharp :: discord bot c# how to refresh message 
Csharp :: c# Prefix Sum of Matrix (Or 2D Array) 
Csharp :: optional parameter get request c# 
Csharp :: how to change the color of a single line of code in c# 
Csharp :: how to get user browser information in .net core 
Csharp :: how to system func bool unity 
Csharp :: c# disable docking sub member in panel 
Csharp :: c# aabb box rotate 
Csharp :: aps.net core mvc chek box 
Csharp :: cors denied error in asp.net core 
Csharp :: how download file from internet and move it to folder with c# 
Csharp :: 1/1/1/1/1 
Csharp :: c# statements 
Csharp :: SETTING UP ARRAY FOR TEST SCORES IN C# 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =