Monday, May 31, 2010
Difference between Assembly and Namespaces
They form the logical boundary for a Group of classes.
Namespace must be specified in Project-Properties.
Assembly: It is an Output Unit. It is a unit of Deployment & a unit of versioning.
Assemblies contain MSIL code.
Assemblies are Self-Describing. [E. g. metadata, manifest]
An assembly is the primary building block of a .NET Framework application. It is a collection of functionality that is built, versioned, and deploymed as a single implementation unit (as one or more files). All managed types and resources are marked either as accessible only within their implementation unit, or by code outside that unit.
'USING' keyword in C#
USING Block- If you declare any unmanaged object in 'USING' block, You need not explicitly dispose that object. Once the block execution is over the dispose() will be called automatically.
What is the difference between Server.Transfer and Response.Redirect?
Response.Redirect(): Using this statement the Context.Items loses the persistence to transfer the content to next page. Hence every page is treated as a seperate page.
What is the difference between a value type and a reference type?
Saturday, May 29, 2010
What are Delegates?
What is versioning in .net
Friday, May 28, 2010
What are valid signatures for the Main functions
Public static void Main(string[] args)
Static Public void Main(string[] args)
Thursday, May 27, 2010
What is the Difference between Boxing and Unboxing
Unboxing :- is Converting Reference type to Value type
Example on Boxing and UnBoxing
namespace Boxing_vs_Unboxing
{
class Program
{
static void Main(string[] args)
{
int i = 1;
object obj = i;//Boxing
Console.WriteLine(obj.ToString());
int j = (int)obj;//Unboxing
Console.WriteLine(i.ToString());
Console.Read();
}
}
}
Difference between String vs. String builder
String - Once the string object is created, its length and content cannot be modified. This method is slower.
String builder - Once the object is created, it can able to modify length and content. This method is faster.
Example on String vs. String builder
namespace stringvsstringbuilder
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("String Example");
string str = string.Empty;
DateTime start = DateTime.Now;
Console.WriteLine("Start time" + start.ToString());
for (long i = 0; i < 100000; i++)
{
str += i.ToString();
}
DateTime stop = DateTime.Now;
Console.WriteLine("Start time" + stop.ToString());
Console.WriteLine("StringBuilder Example");
StringBuilder builder = new StringBuilder();
start = DateTime.Now;
Console.WriteLine("Start time:" + start.ToString());
for (long i = 0; i < 100000; i++)
{
builder.Append(i.ToString());
}
stop = DateTime.Now;
Console.WriteLine("Stop time:" + stop.ToString());
Console.Read();
}
}
}
Tuesday, May 25, 2010
What are Objects
- Object occupies normal variable memory.
- Object is physical representation and we can destroy object memory.
- Object having the lifetime, start time is Constructor and end time is Destructor.
What are Classes
- Class is a user defined data type.
- Classes are like structures in C.
- Class occupies static variables memory and it is a logical representation.
- Memory is continuous until closing the application.
- Classes doesn't have lifetime.
Script for exporting the results in HTML Format
Set FSO = CreateObject("Scripting.FileSystemObject")
IF(FSO.FileExists("C:\log.html"))Then
else
FSO.createTextFile("C:\log.html")
End If
html_logger = "C:\log.html"
environment.value("htmllogfile") = html_logger
set f = FSO.getfile("C:\log.html")
set wr = f.OpenAsTextStream(8,-2)
wr.writeline "<A Name="&chr(34)&"Head"&chr(34)&"><h1>Automation Status Summary Report </h1></A>"
wr.writeline <br><br><br><h5><u>Release</u></h5><br>"
wr.writeline "<h5><u>Build</u></h5><br>
wr.writeline "<h5><u> URL </U></h5><br><br>"
wr.writeline "<hr>"
wr.writeline <style type=text/css>"
wr.writeline "body {"
Monday, May 24, 2010
Saturday, May 22, 2010
Access Specifiers
Scope of the variables
- Public -- Public access modifier can be set to a class / method / property to make it visible to any class / any assembly.
- Private -- Private can be set to those fields which are within the class and they are used to hide from outside of the class.
- Protected -- Protected is used for immediate child classes.
- Internal -- Internal is used specifically for within the assembly.
- Protected Internal -- It is used for within the assembly and assembly that inherits this assembly (Shared Assembly).
- Static @ Modifier -- Static member belongs to the class and as such we don't need to create an object to access it.
- Non-static member - Default, can be accessed only via an object of the class.
Real time: WriteLine() is a static function in Console as we did not create an object that looks like Console to access it.
Destructors
- It takes name of the class but has (~) operator.
- No access specifier.
- Decision to call the destructor is made by a program within C# called the garbage collector.
- Cannot overload a destructor.
Constructors
- Constructors are similar to methods.
- They always take the name of the class but no return type.
- Constructors cannot be called/ inherited can only be invoked by 'new' operator.
- They allocate memory to all of class/member variables to keep default values in it.
- Class has one single constructor & it is private and can never be instantiated.
- Static Constructors -- Used for initializing only static members of a class..These are invoked very first time class is loaded in memory. No args. No Access Modifiers.
- Non-Static Constructors -- Used for initializing static & non-static methods. Invoked every time a new object is created.
Example on Constructor:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
class add
{
public add(int a, int b)
{
int totsum;
totsum = a + b;
MessageBox.Show(totsum.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
add emmu = new add(5, 3);
}
}
Differences between 'const' and 'read-only' in C#
Const | Read-Only |
---|---|
|
|
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
class constvalue
{
public const int conval = 10; //constant initialization
public readonly int tempvalue = conval; //read-only initialization
public constvalue(int rvalue)
{
tempvalue = tempvalue + rvalue; //read-only initialization in constructor
MessageBox.Show(tempvalue.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
constvalue objconstvalue = new constvalue(100);
}
}
What is Data Abstraction:
Data Encapsulation
- Data Encapsulation gave rise to the important concept of data hiding.
- Encapsulation is the ability to hide its data and methods from outside the world and only expose data and methods that are required
- Encapsulation gives us maintainability, flexibility and extensibility to our code.
- Encapsulation is the technique or process of making the fields in a class private and providing access to the fields using public methods.
Example on Data Encapsulation
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
class emp
{
int sal, bonus, ts;
public void tsal()
{
sal = 5000;
bonus = 300;
ts = sal + bonus;
MessageBox.Show(ts.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
emp e1 = new emp();
e1.tsal();
}
}
You concentrate on public method tsal(), change this method to private. here comes encapsulation concept hiding methods from outside world.
Thursday, May 20, 2010
Sunday, May 16, 2010
Saturday, May 15, 2010
Friday, May 14, 2010
Working with File System Object 1
Dim verNum
Set objFSO = CreateObject("Scripting.FileSystemObject")
verNum= objFSO.GetFileVersion("C:\Program Files\Mozilla Firefox\firefox.exe")
MsgBox("Firefox Version"&verNum)
Thursday, May 13, 2010
File System Object Vs Folders
Size a Folder
Copy a Folder
Move a Folder
Delete a Folder
File Count in a folder
SubFolder Count in a Folder
Add a New Folder
Filenames in a folder
SubFoldernames in a Folder
'Syntax:
Copy
FolderObject.Copy(destination[, overwrite])
MoveFolder
FolderObject.MoveFolder(source, destination)
Delete a Folder
FolderObject.DeleteFolder(folderspec[, false])
'Size a Folder
Dim SourceFolder, oFSO
SourceFolder = "C:\IM"
Set oFSO = CreateObject("Scripting.FileSystemObject")
oFSO.GetFolder(SourceFolder)
Msgbox "Size of the Folder "&oFSO.Size&" bytes" 'Display the size of the folder
'Copy a Folder
Dim SourceFolder, oFSO
SourceFolder = "C:\IM"
Set oFSO = CreateObject("Scripting.FileSystemObject")
oFSO.CopyFolder SourceFolder, "D:\"
'Move a Folder
Dim SourceFolder, DestinationFolder, oFSO
SourceFolder = "C:\IM"
DestinationFolder = "D:\"
Set oFSO = CreateObject("Scripting.FileSystemObject")
oFSO.MoveFolder SourceFolder, DestinationFolder
'Delete a Folder
Dim SourceFolder, oFSO
SourceFolder = "D:\IM"
Set oFSO = CreateObject("Scripting.FileSystemObject")
oFSO.DeleteFolder SourceFolder
'Get the File Count in a folder
Set FSO = CreateObject("Scripting.FileSystemObject")
FolderPath = "C:\Documents and Settings\"
Set TestFolder = FSO.GetFolder(FolderPath)
Set Files = TestFolder.Files
MsgBox("Number of Files in:"&vbCrLf&FolderPath&vbcrlf&Files.Count)
'Get the SubFolder Count in a Folder
Set FSO = CreateObject("Scripting.FileSystemObject")
Set TestFolder = FSO.GetFolder("C:\Documents and Settings")
Set SubFolders = TestFolder.SubFolders 'Returns the collection of subfolders
Msgbox(SubFolders.Count)
'Add a New Folder
Sub AddNewFolder(FolderPath, FolderName)
Dim FSO, f, fc,nf
Set FSO = CreateObject("Scripting.FileSystemObject")
Set f = FSO.GetFolder(FolderPath)
Set fc = f.SubFolders
If FolderName <> "" Then
Set nf = fc.Add(FolderName)
Else
Set nf = fc.Add("New Folder")
End If
End Sub
AddNewFolder "C:\",""
'Filenames in a Folder
Folderpath = "C:\MyFolder"
Dim FSO, oFolder
Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = FSO.GetFolder(FolderPath)
Files = oFolder.Files 'Gets the collection of files in a folder
For each file in Files
Msgbox File.Name
Next
'SubFoldernames in a Folder
Folderpath = "C:\MyFolder"
Dim FSO, oFolder
Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = FSO.GetFolder(FolderPath)
Folders = oFolder.SubFolders 'Gets the collection of subfolders in a folder
For each folder in Folders
Msgbox folder.Name
Next
File System Object Vs Drives
Drive Information
Drive Name of a specified file path
Drive is Ready or Not
'Total Number of Drives in your System
Set FSO = CreateObject("Scripting.FileSystemObject")
Set DriveCollection= FSO.Drives 'A collection of drive objects
MsgBox("Total Number of Drives available in your system: "&DriveCollection.Count)
'Drive Information in your System
Set FSO = CreateObject("Scripting.FileSystemObject")
intDrive = 0
For Each Driver in FSO.Drives
Msgbox "Name of the Drive :"&Driver.DriveLetter
Select Case Driver.DriveType
Case 0: strDriveType = "Drive type cannot be determined"
Case 1: strDriveType = "Removable Drive"
Case 2: strDriveType = "Fixed Drive"
Case 3: strDriveType = "CD-ROM"
Case 4: strDriveType = "RAM Disk"
End Select
msgbox "Type of the Drive : "&strDriveType
If(Driver.DriveType = 2)Then
msgbox "Total Size of the Specified Drive: "&Driver.Totalsize
msgbox "Free Space available in the Drive: "&Driver.FreeSpace
msgbox "Available Space in the Drive: "&DriverAvailableSpace
msgbox "File System of the specified Drive: "&Driver.FileSystem
'Available File Systems are FAT, NTFS and CDFS
msgbox "Serial Number of the specified Drive: "&Driver.SerialNumber
msgbox "Share Name of the specified Drive: "&Driver.ShareName
msgbox "Volume Name of the specified Drive: "&Driver.VolumeName
End If
intDrive = intDrive + 1
Next
'Drive Name of a specified file path
DrvPath = "D:\debugnew.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set GetDriveInfo = fso.GetDriveName(drvPath)
Msgbox ("Name of the Drive :"&GetDriveInfo)
'Drive is Ready or Not
DrvPath = "D:\debugnew.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set GetDriveInfo = fso.GetDrive(fso.GetDriveName(drvPath))
If GetDriveInfo.IsReady Then
Msgbox "Drive is Ready"
Else
Msgbox "Drive is Not Ready"
End If
Monday, May 10, 2010
Sunday, May 9, 2010
Saturday, May 8, 2010
Thursday, May 6, 2010
Tuesday, May 4, 2010
Comments
Example:
\'This is a single line comments
\''This is another single line comment
CoolTuts - JavaScript - JavaScript Comments
Comments can be added JavaScript, to make the code more readable.
Single line comments start with //.
JavaScript multiple line Comments
Multi line comments start with /* and end with */.