Return multiple values from a C# asynchronous method

After playing with the code I was able to figure it out. Here is the solution. 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}”; … Read more

How to obtain the results from a pool of threads in python?

In Python 3.x, you can use concurrent.futures.ThreadPoolExecutor to do this, rather than rolling your own. Python 2.x actually has a built-in thread pool you can use as well, its just not well documented: from multiprocessing.pool import ThreadPool def foo(word, number): print (word * number) r[(word,number)] = number return number words = [‘hello’, ‘world’, ‘test’, ‘word’, … Read more

How to return a value from try, catch, and finally?

To return a value when using try/catch you can use a temporary variable, e.g. public static double add(String[] values) { double sum = 0.0; try { int length = values.length; double arrayValues[] = new double[length]; for(int i = 0; i < length; i++) { arrayValues[i] = Double.parseDouble(values[i]); sum += arrayValues[i]; } } catch(NumberFormatException e) { … Read more

Can I avoid casting an enum value when I try to use or return it?

enums are supposed to be type safe. I think they didn’t make them implicitly castable to discourage other uses. Although the framework allows you to assign a constant value to them, you should reconsider your intent. If you primarily use the enum for storing constant values, consider using a static class: public static class ReturnValue … Read more

Can a C++ function be declared such that the return value cannot be ignored?

To summarize from other answers & comments, basically you have 3 choices: Get C++17 to be able to use [[nodiscard]] In g++ (also clang++), use compiler extensions like __wur (defined as __attribute__ ((__warn_unused_result__))), or the more portable (C++11 and up only) [[gnu::warn_unused_result]] attribute. Use runtime checks to catch the problem during unit testing If all … Read more

techhipbettruvabetnorabahisbahis forumu