c# - Difference in instantiating a variable using parenthesis and not -


this question has answer here:

difference in instantiating variable using parentencis , not

with parentheses

var mycity = new citydto() {    id = 1,    name = "ny" }; 

without parentheses

var mycity = new citydto {    id = 1,    name = "ny" }; 

there's no difference. when calling default constructor, using object initializer syntax, () can removed.

if remove object initializer, () required.


Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

laravel - Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id (View: F:\project\resources\views\admin\carousels\index.blade.php) -