Programming Tutorials on XHTML, CSS, JavaScript, JQuery, JSON, Python, Django, Amazon Web Services, ASP.NET, Web Forms, and SQL
Sunday, July 1, 2012
const and readonly in C# .NET
What is the difference between const and readonly in C#.NET?
The read only can be modified by the class it is contained in. However, the const cannot be modified. It needs to be instantiated only at the compile time.
Generics in C# .NET
What are generics in C#.NET?
Generic types to maximize code reuse, type safety, and performance. They can be used to create collection classes. Generic collection classes in the System.Collections.Generic namespace should be used instead of classes such as ArrayList in the System.Collections namespace.
or
Generics allow you to define type-safe data structures, without committing to actual data types. It allows writing less but more effective code. Generic provides flexibility and power but the developer needs to be responsible while using it.
Friday, June 29, 2012
Java Script Tutorial 25 : JavaScript RegExp Object
A regular expression (RegExp) is an object that describes a pattern of characters. When you search in a text, you can use a pattern to describe what you are searching for. A simple pattern can be one single character. A more complicated pattern can consist of more characters, and can be used for parsing, format checking, substitution and more.
Regular expressions are used to perform powerful pattern-matching and search-and-replace functions on text. Syntax of RegExp is as follow :
var patterntxt=new RegExp(somepattern,modifiers);
or
var patt=/somepattern/modifiers;
In above code, somepattern specifies the pattern of an expression. modifiers specify if a search should be global, case-sensitive, etc.
RegExp Modifiers are used to perform case-insensitive and global searches. For example we use i modifier for case-insensitive matching and g modifier for global match. Global match means, find all matches rather than stopping after the first match. For example
var str1 = "This is some text.";
var pattern = /some text/i;
document.write(str1.match(pattern));
The result of above case-sensitive search will be : some text
The test() method searches a string for a specified value, and returns true or false, depending on the result. For example
var pattern=new RegExp("s");
document.write(pattern.test("The sun rises in the east"));
Result of above code will be "true", as it contains the "s" string.
The exec() method searches a string for a specified value, and returns the text of the found value. It return null, in case no match found. For example
var pattern=new RegExp("s");
document.write(pattern.exec("The sun rises in the east."));
Result of above code will be "s", as it contains the "s" string.
Java Script Tutorial 24 : JavaScript Math Object
The Math object allows you to perform mathematical tasks. The Math object includes several mathematical constants and methods. Syntax for using properties/methods of Math is as follows:
var x=Math.PI;
var y=Math.sqrt(16);
There is eight mathematical constants in JavaScript that can be accessed from the Math object. These mathematical constants are :
E
PI
square root of 2
square root of 1/2
natural log of 2
natural log of 10
base-2 log of E
base-10 log of E.
We can call/reference these constants from JavaScript as below:
Math.E
Math.PI
Math.SQRT2
Math.SQRT1_2
Math.LN2
Math.LN10
Math.LOG2E
Math.LOG10E
There are many mathematical methods also available in JavaScript. For example Math.round() is used to round a number, e.g
document.write(Math.round(9.8));
Result of above code will be : 10
Math.random() method of the Math object is used to generate random numbers. For example
document.write(Math.random());
Result of above code can be anything between 0 and 1.
We can set the limit of random number generation( by using arguments ). For example, the following code return random number between 0 and 20.
Math.random()*21)
To generate random number from 0 and 100 change 21 to 101.
var x=Math.PI;
var y=Math.sqrt(16);
There is eight mathematical constants in JavaScript that can be accessed from the Math object. These mathematical constants are :
E
PI
square root of 2
square root of 1/2
natural log of 2
natural log of 10
base-2 log of E
base-10 log of E.
We can call/reference these constants from JavaScript as below:
Math.E
Math.PI
Math.SQRT2
Math.SQRT1_2
Math.LN2
Math.LN10
Math.LOG2E
Math.LOG10E
There are many mathematical methods also available in JavaScript. For example Math.round() is used to round a number, e.g
document.write(Math.round(9.8));
Result of above code will be : 10
Math.random() method of the Math object is used to generate random numbers. For example
document.write(Math.random());
Result of above code can be anything between 0 and 1.
We can set the limit of random number generation( by using arguments ). For example, the following code return random number between 0 and 20.
Math.random()*21)
To generate random number from 0 and 100 change 21 to 101.
Thursday, June 28, 2012
Java Script Tutorial 23 : JavaScript Boolean Object
The JavaScript Boolean object represents two values, "true" or/and "false". We can create a Boolean object in javascript as follows :
var myBooleanObj=new Boolean();
Javascript boolean object will set to false, if we do not set its initial value or has one of the following values:
0
-0
null
""
false
undefined
NaN
It will be true for any other value.
Subscribe to:
Posts (Atom)