Skip to main content

Posts

JAVASCRIPT USEFUL VALIDATIONS

Allow only numbers to be entered inside Textbox. function isNumberKey(evt) { var charCode = (evt.which) ? evt.which : event. keyCode if (charCode > 31 && (charCode < 48 || charCode > 57)) return false; return true; } <asp:TextBox ID="txtnum" runat=" server " onkeypress="return isNumberKey(event)"></asp:TextBox> Allow only characters to be entered inside Textbox like Name’s textbox. function noNumbers(e) { var keynum; var keychar; var numcheck; if ( window .event) // IE8 and earlier { keynum = e.keyCode; } else if (e.which) // IE9/Firefox/ Chrome /Opera/Safari { keynum = e.which; } keychar = String.fromCharCode(keynum); numcheck = /\d/; return !numcheck.test(keychar); } ...

Sealed Class AND PARTIAL CLASS

  Classes can be declared as sealed . This is accomplished by putting the sealed keyword before the keyword class in the class definition Sealed classes are used to restrict the inheritance feature of object oriented programming . Once a class is defined as sealed class , this class cannot be inherited. A sealed class cannot be used as a base class . For this reason, it cannot also be an abstract class. Sealed classes are primarily used to prevent derivation. Because they can never be used as a base class, some run-time optimizations can make calling sealed class members slightly faster. class Class1 { static void Main(string[] args) { SealedClass sealedCls = new SealedClass(); int total = sealedCls.Add(4, 5); Console.WriteLine("Total = " + total.ToString()); } } // Sealed class sealed class SealedC...

Enums

An enum is basically a value type with a set of related named constants often which is referred to as an enumerator list. The enum keyword is for declaring an enumeration. An Enumeration is a primitive data type which is user defined data type. An Enum is basically used to create numeric constants in .NET framework. All the member of an enum are of enum type and there must be a numeric value for an each enum type. Enums type can be integer (float, int, byte, double etc.). But if you used beside int it has to be cast. Every enum type automatically derives from System.Enum and thus we can use System.Enum methods on enums. class Program { public enum DayoftheWeek { Sunday = 1, Monday = 2, Tuesday = 3, Wednesday = 4, Thursday = 5, Friday = 6, ...

Generics

Generics allow us to have type or method which can operate on objects of various types, while providing type safety at the compile time. That means if you define generics class object of type Integer & you are trying to add different type of variable to generic class like String then it will give compile time error. In another sense, if we try to add different types in same list like string and int in a same list then compile time error will be thrown. Generics are available under the namespace System. Collections .Generic. The concept of type parameters is introduce to the .NET Framework with the help of Generics, which makes it possible to design classes & methods which defer the specification of one or more types until that class or method is declared and instantiated by the client code. public class MyGenericClass { void Add(T val) { } ...

Interface

   Interface is nothing but an contract of the system which can be implemented on accounts. .Net doesn't support the multiple inheritance directly but using interfaces we can achieve multiple inheritance in .net. An Interface can only contains abstract members and it is a reference type. Interface members can be Methods, Properties, Events and Indexers. But the interfaces only contains declaration for its members. Class which inherits interface needs to implement all it's methods. All declared interface member are implicitly public. class Program { interface BaseInterface { void BaseInterfaceMethod(); } interface DerivedInterface : BaseInterface { void DerivedToImplement(); } class InterfaceImplementer : DerivedInterface { public void DerivedToImplement() { Console.WriteLine("Method of Derived Interfac...

Abstraction

Abstraction refers to the act of representing essential features without including the background details or explanations. Abstraction defines way to abstract or hide your data and members from outside world. Classes use the concept of abstraction and are defined as a list of abstract attributes. Simply speaking Abstraction is hiding the complexities of your class or struct or in a generic term Type from outer world. This is achieved by means of access specifiers. Access Modifier Description (who can access) Private Only members within the same type.  (default for type members) Protected ...