I am starting and studying web development using ASP.Net MVC 5 in C #. I came across the code below:
Scenrio 1: No New Keyword used when creating objects.
[AuthorizeFunc] [BlockWidget] public PartialViewResult WidgetPayments() { PaymentFormMV data; // No New Keyword used if (SimUtils.IsDelayedPaymentAllowed) { data = Pay.GetData(PaymentPageMode.DelayedPayment); } else { data = PayHelp.GetData(PaymentPageMode.MakePayment); } return PartialView("PaymentsWrapper", data); }
Scenrio 2: New Keyword used when creating objects.
[AuthorizeFunc] [BlockWidget] public PartialViewResult WidgetPayments() { PaymentFormMV data = new PaymentFormMV(); // New Keyword used if (SimUtils.IsDelayedPaymentAllowed) { data = Pay.GetData(PaymentPageMode.DelayedPayment); } else { data = PayHelp.GetData(PaymentPageMode.MakePayment); } return PartialView("PaymentsWrapper", data); }
I am starting and I have tried both codes, and both codes work fine for me.
Question 1: Why do both codes work fine?
Question 2: When to use the βnewβ and when not to βuseβ. Can someone tell me one example for both scenarios.
Question 3: What is the difference between the two.
Can someone please guide me a little.
source share