Although there are strong similarities between C# constructors and C++ constructors, there are, also, some significant differences.
Firstly, C# supports constructor chaining—one constructor can call another.
example: class Employee { public Employee (string name, int salary) { ... }
public Employee (string name) : this (salary, 0) {}
public Employee() : this ("", 0) {} }
Secondly, virtual method calls within a constructor are directed to the most derived implementation.
Thirdly, error handling is a bit different. When an exception occurs during C# object construction, the destructor—finalizer—will be called. This behavior differs from C++ behavior in which the destructor is not called if construction is interrupted.
Lastly, C# has static constructors. A static constructor for a class executes before the first instance of the class is created.
Interestingly, some C# developers—like some C++ developers—prefer the factory pattern to constructors.
what is the regex pattern for 3 digits with hyphen 3 digits like this 79-90. i want to validate one textbox.
ReplyDeletehi nithin.
ReplyDeleteyou just try this code..
Regex regStr = new Regex(@"^\d{1,3}[-]\d{1,3}$");
Thanks.
hi.. i need regex exprn to accept all phone numbers.. help me please
ReplyDeletehii shafi,
ReplyDeletecheck this one.
^((\+){0,1}91(\s){0,1}(\-){0,1}(\s){0,1}){0,1}98(\s){0,1}(\-){0,1}(\s){0,1}[1-9]{1}[0-9]{7}$
or
^(\([2-9]|[2-9])(\d{2}|\d{2}\))(-|.|\s)?\d{3}(-|.|\s)?\d{4}$
thanks
Are constructors the same in C++ and C#?
ReplyDeletehiii...
ReplyDeleteAlthough there are strong similarities between C# constructors and C++ constructors, there are, also, some significant differences.
Firstly, C# supports constructor chaining—one constructor can call another.
example:
class Employee
{
public Employee (string name, int salary)
{ ... }
public Employee (string name) : this (salary, 0) {}
public Employee() : this ("", 0) {}
}
Secondly, virtual method calls within a constructor are directed to the most derived implementation.
Thirdly, error handling is a bit different. When an exception occurs during C# object construction, the destructor—finalizer—will be called. This behavior differs from C++ behavior in which the destructor is not called if construction is interrupted.
Lastly, C# has static constructors. A static constructor for a class executes before the first instance of the class is created.
Interestingly, some C# developers—like some C++ developers—prefer the factory pattern to constructors.
How c# handles object copying? like c++ have a copy constructor
ReplyDelete