KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
First of all i searched on this and i found the following links on Stack Overflow: Is there any difference between `new object()` and `new {}` in c#? Difference between object a = new Dog() vs Dog a = new Dog() But i'm not satisfied with this answer, it's not explained well (i didn't get it well). Basically, i want to know the difference between new object() and new {} . How, they are treated at compile time and runtime? Secondaly, i have the following code which i have used for WebMethods in my asp.net simple application [WebMethod] [ScriptMethod(UseHttpGet = false)] public static object SaveMenus(MenuManager proParams) { object data = new { }; // here im creating an instance of an 'object' and i have typed it `new {}` but not `new object(){}`. try { MenuManager menu = new MenuManager(); menu.Name = proParams.Name; menu.Icon = proParams.Icon; bool status = menu.MenuSave(menu); if (status) { // however, here i'm returning an anonymous type data = new { status = true, message = "Successfully Done!" }; } } catch (Exception ex) { data = new { status = false, message = ex.Message.ToString() }; } return data; } So, (as you can see in comments in code), How new object(){} and new {} differences? Is this even the right way that i have write the code? Can you suggest a best way for this code? I know, i can't explain it well and i'm asking alot, b
Tags (comma-separated)
Save Edits
Cancel