Why use new in c#
Hi
Why we use (new) in every object in c# for example(SQL command cmd=new sqlcommand())?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Dharmraj ThakurRank #577 · 4.2K reputationPosted Jun 2, 2017, 12:23 AM EDT
It is used to create instances of anonymous types.
The
newoperator is also used to invoke the default constructor for value types.The
newoperator cannot be overloaded.If the
newoperator fails to allocate memory, it throws the exception, OutOfMemoryException.