首页 \ 问答 \ 空构造函数或无构造函数(Empty constructor or no constructor)

空构造函数或无构造函数(Empty constructor or no constructor)

我认为在类(C#)中有一个默认的构造函数是不是必须的。

那么在这种情况下,我有一个空的建设者在课堂上还是我可以跳过它?

有空的默认构造函数是最佳做法吗?

Class test
{
   public test()
   {

   }
        ......
}

要么

Class test
{
        ......
}

I think it is not mandatory to have a default constructor in a class (C#).

So, in that situation shall I have an empty constructor in the class or can I skip it?

Is it a best practice to have an empty default constructor?

Class test
{
   public test()
   {

   }
        ......
}

or

Class test
{
        ......
}

原文:https://stackoverflow.com/questions/2963742
更新时间:2023-11-26 16:11

最满意答案

为此使用jquery:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>

并调用函数

$(document).ready(function(){

    $.post('localhost:5000/registrar', {
      "enrollId": "jim",
      "enrollSecret": "6avZQLwcUe9b"
    }, function(serverResponse){

    //do what you want with server response

    })

})

同样没有速记来处理错误:

$.ajax({
  type: "POST",
  url: 'localhost:5000/registrar',
  data: {
      "enrollId": "jim",
      "enrollSecret": "6avZQLwcUe9b"
    },
  success: function(){$('#register').html('<h1>Login successfull</h1>');},
  error: function(){$('#register').html('<h1>Login error</h1>');},
  dataType: dataType
});

Use jquery for this:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>

And call function

$(document).ready(function(){

    $.post('localhost:5000/registrar', {
      "enrollId": "jim",
      "enrollSecret": "6avZQLwcUe9b"
    }, function(serverResponse){

    //do what you want with server response

    })

})

Same without shorthand to handle errors:

$.ajax({
  type: "POST",
  url: 'localhost:5000/registrar',
  data: {
      "enrollId": "jim",
      "enrollSecret": "6avZQLwcUe9b"
    },
  success: function(){$('#register').html('<h1>Login successfull</h1>');},
  error: function(){$('#register').html('<h1>Login error</h1>');},
  dataType: dataType
});

相关问答

更多
  • 为此使用jquery: 并调用函数 $(document).ready(function(){ $.post('localhost:5000/registrar', { "enrollId": "jim", "enrollSecret": "6avZQLwcUe9b" }, functio ...
  • 如果仔细比较你的JSON和文档中的JSON,你会在数据之前和之后有一个额外的" 。这意味着你发布了一个大的字符串,而不是一个JSON对象。 解决方法是从开始和结束删除多余的双引号。 这也意味着你不再需要转义JSON中的双引号: '{"senderId":"CBPA9tdrNyc1Y3AxSb8rkZjDJxh2","senderName":"John","text":"Hello its me"}' 如果您用于发布的工具尝试将JSON解析为单个字符串,则需要单引号。 如果没有(提示:hurl.it没有), ...
  • 不要使用POST。 根据文件 : 要完成JavaScript push()方法(请参阅数据列表)的等价物,您可以发出POST请求。 你不想在这里推。 推送操作会创建一个新的随机推送ID并使其成为您提供的数据的关键。 如果你已经知道你想要设置的位置(它看起来像你已经有一个已知的推送ID),只需使用PUT来设置该位置的数据。 Don't use POST. According to the documentation: To accomplish the equivalent of the JavaScript ...
  • 你可以从这样的事情开始 服务 export class MyService{ constructor( private httpClient: HttpClient) { } getSomethingFromServer():Observable{ return this.httpClient.get('you_request_url'); } } 零件 constructor( private myService: MyService) { ...
  • 例外信息中明确说明了这个问题: Can not deserialize instance of long out of START_OBJECT 当杰克逊在你的JSON请求正文中找到一个起始{字符时,它不能反序列化一长串。 在如下模型中包装id应该就足够了: public class MyModel { private Long id; // use primitive type if, as I would think, id cannot be null public void se ...
  • 我错过了:现在我可以得到正确的Base64值并连接到授权头并且它的工作正常 I was missing the : thing now I can get the correct Base64 value and concatenate to authorization header and its working fine
  • 错误代码404表示文件不是fount。 您的api链接不是文件名退出。 请添加完整的api路径,例如 developer.b24solutions.com/grocery/api/rest/yourfilename 因为此链接在浏览器中不起作用。 您的代码是正确的但不正确的api链接。 NSURL *myURL = [NSURL URLWithString:@"http://developer.b24solutions.com/grocery/api/rest/giveyourfilenamewithext ...
  • 错误 JsonMappingException是Jackson的一个例外,它是Java的JSON解析器。 它表示将JSON映射到Java bean时会出现致命问题。 在这种情况下,看起来像字符串2016-04-11无法从Java 8解析为LocalDate 。 如何解决它 Jackson支持Java 8日期类型,但需要以下依赖项: com.fasterxml.jackson.datatype jackso ...
  • 听起来你正在使用Django REST Framework,在这种情况下TokenAuthentication可能是合适的。 从文档: 此认证方案使用简单的基于令牌的HTTP认证方案。 令牌认证适用于客户端 - 服务器设置,例如本机桌面和移动客户端 您不需要预先生成令牌,因为客户端可以使用您在urls.py中配置的内置视图obtain_auth_token来请求令牌。 一旦客户端获得会话标记,他们就可以使用Authorization: HTTP标头在随后的API调用中提供它。 查看文档以获取更多信息: ht ...
  • 要回答您的问题,是的,REST API是您希望将其公开给创建用户,发布条目等的任何客户端的集合。接受的数据格式是您为API决定的。 它可能是JSON,XML甚至两者。 一些例子: http://coenraets.org/blog/2011/12/restful-services-with-jquery-php-and-the-slim-framework/ http://peter.neish.net/building-a-mobile-app-于后端的使用-mongodb的和超薄-A-PHP-其余的框架 ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)