For Developers

setInterval Method in Javascript

The setInterval() method evaluates a function or an expression repeatedly for the specified number of milliseconds and it returns an interval reference.

Syntax:


variable = setInterval(expression, milliseconds)
or
variable = setInterval(function, milliseconds)

variable holds the interval reference returned by seInterval method


Example:
Below example display the current time information using setInterval method call the date object.

< html>
< head>
< title> setInterval Method Example </title>
< script language="javascript">
function startSetInt()
{
ref=setInterval("init()",100);
}

function init()
{
dt = new Date();
document.getElementById("lbl").innerText = "Timer : " + dt;
document.getElementById("btnStart").disabled = true;
document.getElementById("btnStop").disabled = false;
}

function stopSetInt()
{
clearInterval(ref)
document.getElementById("lbl").innerText = "Timer : ";
document.getElementById("btnStart").disabled = false;
document.getElementById("btnStop").disabled = true;
}
</script>
</head>
< body onload="startSetInt()">
< label id="lbl" name="lbl"></label>
</br>
</br>
< input type="button" id="btnStart" value="Start" onclick="startSetInt()" />
< input type="button" id="btnStop" value="Stop" onclick="stopSetInt()" />
</body>
</html>

Demo : Click here

JSON Data types and Example

The following are the Basic JSON Data types,


  • Number : integer, real, or floating point
  • String : double-quoted Unicode with backslash escaping
  • Boolean : true and false
  • Array : an ordered sequence of values, comma-separated and enclosed in square brackets
  • Object : collection of key:value pairs, comma-separated and enclosed in curly braces
  • null


Example


{
"firstName": "Praveen",
"lastName": "C",
"address": {
"streetAddress": "KK Nagar",
"city": "Chennai",
"state": "TN",
"postalCode": 6310102
},
"phoneNumbers": [
"091 98943 37266"
]
}

What is JSON?

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others.

Get available server names of Sql Server within the local network - SqlDataSourceEnumerator

SqlDataSourceEnumerator is a class in .net framework that gets the available instances of SQL Server within the local network.


DataTable dt = SqlDataSourceEnumerator.Instance.GetDataSources();


SqlDataSourceEnumerator.Instance.GetDataSources() returns a datatable with the available servers in the current network.

The DataTable returned as 4 colunms such as :-
  • ServerName
  • InstanceName
  • IsClustered
  • Version

Sorting Program using C#


namespace SortingNos
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter Numbers :");
int[] arr = new int[5];
string arr1 = "";
for (int i = 0; i < 5; i++)
{
arr1 = Console.ReadLine();
arr[i] = Convert.ToInt32(arr1);
}

int a, b, temp = 0;
Console.WriteLine();
for (a = 0; a < arr.Length; a++)
{
for(b=a+1;b< arr.Length;b++)
{
if (arr[a] > arr[b])
{
temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
}
}
Console.WriteLine(arr[a]);
}
Console.ReadLine();
}
}
}


Download