public ResponseResult GetUserInfo(string userId) { // Get user info from database var user = _userRepository.GetUserById(userId); // Build response object var response = ResponseResult.GetSuccessObject("User info retrieved successfully", user); return response; }
if(user != null) { ResponseResult response = ResponseResult.GetSuccessObject("User Info Retrieved Successfully", user); return Ok(response); }In this example, the method is used to build a response object in a conditional statement. If the user information is retrieved successfully from the database, the response object is built using the GetSuccessObject method and returned to the client with an Ok HTTP status code. The library or package that contains the ResponseResult class and the GetSuccessObject method may vary depending on the framework or library being used, but commonly used packages/libraries for building APIs in C# include ASP.NET Core, Nancy, and ServiceStack.