• <bdo id='uaiGQ'></bdo><ul id='uaiGQ'></ul>
    <legend id='uaiGQ'><style id='uaiGQ'><dir id='uaiGQ'><q id='uaiGQ'></q></dir></style></legend>
  • <small id='uaiGQ'></small><noframes id='uaiGQ'>

    1. <i id='uaiGQ'><tr id='uaiGQ'><dt id='uaiGQ'><q id='uaiGQ'><span id='uaiGQ'><b id='uaiGQ'><form id='uaiGQ'><ins id='uaiGQ'></ins><ul id='uaiGQ'></ul><sub id='uaiGQ'></sub></form><legend id='uaiGQ'></legend><bdo id='uaiGQ'><pre id='uaiGQ'><center id='uaiGQ'></center></pre></bdo></b><th id='uaiGQ'></th></span></q></dt></tr></i><div id='uaiGQ'><tfoot id='uaiGQ'></tfoot><dl id='uaiGQ'><fieldset id='uaiGQ'></fieldset></dl></div>

        <tfoot id='uaiGQ'></tfoot>

        Ok() 方法 new ObjectResult() 有什么区别吗?

        Is there any difference between the Ok() method new ObjectResult()?(Ok() 方法 new ObjectResult() 有什么区别吗?)
        <i id='5cwj2'><tr id='5cwj2'><dt id='5cwj2'><q id='5cwj2'><span id='5cwj2'><b id='5cwj2'><form id='5cwj2'><ins id='5cwj2'></ins><ul id='5cwj2'></ul><sub id='5cwj2'></sub></form><legend id='5cwj2'></legend><bdo id='5cwj2'><pre id='5cwj2'><center id='5cwj2'></center></pre></bdo></b><th id='5cwj2'></th></span></q></dt></tr></i><div id='5cwj2'><tfoot id='5cwj2'></tfoot><dl id='5cwj2'><fieldset id='5cwj2'></fieldset></dl></div>

            <tfoot id='5cwj2'></tfoot>

              <tbody id='5cwj2'></tbody>
            <legend id='5cwj2'><style id='5cwj2'><dir id='5cwj2'><q id='5cwj2'></q></dir></style></legend>

            <small id='5cwj2'></small><noframes id='5cwj2'>

            • <bdo id='5cwj2'></bdo><ul id='5cwj2'></ul>
                1. 本文介绍了Ok() 方法 new ObjectResult() 有什么区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  场景:在 .net 核心控制器上实现标准 REST API/GET 方法.

                  Scenario: implementing a standard REST API / GET method on a .net core controller.

                  文档指出 OkObjectResult是一个状态为 200 的 ObjectResult.这可通过从 ControllerBase 继承的 Ok(myResult) 方法获得.我认为这是一种方便的方法.

                  The documentation states that OkObjectResult is an ObjectResult with status 200. This is available through the Ok(myResult) method inherited from ControllerBase. I assume this is a convenience method.

                  但是,教程没有使用这种方法 - 它改为返回 new ObjectResult(myResult) ,默认状态为 200.

                  However, the tutorial is not using this approach - it instead returns new ObjectResult(myResult) which will default to status 200.

                  这两种方法有什么区别吗?

                  Is there any difference between these two approaches?

                  推荐答案

                  技术上这两种方法没有区别.

                  如果你想看OkObjectResult 那么你会看到 OkObjectResult 是一个 ObjectResult 设置200状态码,这是默认的ObjectResult 已经.

                  If you want to look at the code of OkObjectResult then you will see that the OkObjectResult is an ObjectResult that sets the 200 status code, which is the default of ObjectResult already.

                  对我而言,唯一的区别是代码的可读性以及您自己或您的团队的偏好.这完全取决于命名以及您要强调的意图.

                  The only difference for me is readability in code and your own or your team preferences. It is all about naming and what intention you want to stress.

                   return Ok(myResult);                  // gives emphasis on status, my personal favorite
                  
                   return new OkObjectResult(myResult);  // for me a little bit verbose and the same
                                                         // effect as Ok; but states we return an Object
                  
                   return new ObjectResult(myResult);    // gives emphasis of the content that is returned
                  

                  这篇关于Ok() 方法 new ObjectResult() 有什么区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  C# Attributes and their uses(C# 属性及其用途)
                  C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)

                    <tbody id='D2zpV'></tbody>
                    • <bdo id='D2zpV'></bdo><ul id='D2zpV'></ul>
                      <tfoot id='D2zpV'></tfoot>
                          <i id='D2zpV'><tr id='D2zpV'><dt id='D2zpV'><q id='D2zpV'><span id='D2zpV'><b id='D2zpV'><form id='D2zpV'><ins id='D2zpV'></ins><ul id='D2zpV'></ul><sub id='D2zpV'></sub></form><legend id='D2zpV'></legend><bdo id='D2zpV'><pre id='D2zpV'><center id='D2zpV'></center></pre></bdo></b><th id='D2zpV'></th></span></q></dt></tr></i><div id='D2zpV'><tfoot id='D2zpV'></tfoot><dl id='D2zpV'><fieldset id='D2zpV'></fieldset></dl></div>

                          <small id='D2zpV'></small><noframes id='D2zpV'>

                          <legend id='D2zpV'><style id='D2zpV'><dir id='D2zpV'><q id='D2zpV'></q></dir></style></legend>