Dot Net Framework
Dot Net Framework
2) Checked Property:
The Checked property indicates whether a particular radio button is
selected or not. It is a boolean property, and when set to true, it means
the radio button is selected, and when set to false, it means the radio
button is not selected.
Typically, only one radio button in a group should have the Checked
property set to true at a time, as the purpose of radio buttons is to allow
a single selection from the group.
5)Load:
The Load event is triggered. Developers commonly use this event to
perform tasks such as populating controls, retrieving data, or handling
user input.
During this stage, data-bound controls are populated, and control
properties are set based on the ViewState and postback data.
6)Raise Postback Event:
If the page is being processed in response to a postback, the control that
caused the postback triggers its corresponding event during the
RaisePostBackEvent event.
For example, a button click triggers the Click event.
7)PreRender:
The PreRender event is triggered. Developers often use this event to
perform final changes to the page or its controls before rendering.
During this stage, changes made to controls are persisted, and the
ViewState is updated.
8)Save State (Save ViewState):
The SaveViewState event is triggered, allowing controls to save their
state information to the ViewState.
The state information includes properties that need to be persisted
across postbacks.
9)Save Postback Data:
If controls implement IPostBackDataHandler, the SavePostData event is
triggered to allow them to save their postback data.
This stage is crucial for maintaining state across postbacks.
10)Render:
The Render event is triggered, and the HTML markup for the page is
generated.
During this stage, the output for controls is rendered, and the resulting
HTML is sent to the browser.
11)Unload:
The Unload event is triggered. Developers can use this event for final
cleanup tasks before the page is unloaded from memory.
After the Unload event, the page is disposed of.
2) SqlCommand:
Represents a SQL statement or stored procedure to execute against a
SQL Server database.
Used to execute queries, updates, inserts, and other SQL operations.
Example:
using (SqlCommand command = new SqlCommand("SELECT * FROM
Customers", connection))
{
SqlDataReader reader = command.ExecuteReader();
// Process the results
}
3) SqlDataAdapter:
Represents a set of data commands and a database connection for
populating a DataSet and updating the database.
Acts as a bridge between a DataSet and a database.
Example:
using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM
Products", connection))
{
DataSet dataSet = new DataSet();
adapter.Fill(dataSet, "Products");
// Work with the DataSet
}
4) DataSet:
Represents an in-memory cache of data retrieved from a data source.
Consists of one or more DataTable objects, each representing a table of
data.
Example:
DataSet dataSet = new DataSet();
dataSet.Tables.Add(new DataTable("Customers"));
5) DataTable:
Represents an in-memory table of data within a DataSet.
Contains rows and columns, much like a database table.
Example:
DataTable dataTable = new DataTable("Orders");
dataTable.Columns.Add("OrderID", typeof(int));
dataTable.Columns.Add("CustomerID", typeof(string));
6) DataReader:
Provides a forward-only, read-only stream of data from a data source.
Typically used for retrieving large result sets efficiently.
Example:
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
// Process each row
}
}
7) SqlParameter:
Represents a parameter to a SqlCommand and optionally its mapping to
DataSet columns.
Used to pass parameters to SQL queries or stored procedures.
Example:
SqlCommand command = new SqlCommand("INSERT INTO Employees
(FirstName, LastName) VALUES (@FirstName, @LastName)",
connection);
command.Parameters.Add(new SqlParameter("@FirstName", "John"));
command.Parameters.Add(new SqlParameter("@LastName", "Doe"));
8) SqlTransaction:
Represents a transaction to be made in the SQL Server database.
Provides methods for committing or rolling back a transaction.
Example:
using (SqlTransaction transaction = connection.BeginTransaction())
{
// Execute SQL commands within the transaction
transaction.Commit();
}
Syntax:
If condition Then
' Code to execute if the condition is true
Else
' Code to execute if the condition is false
3)End If
Explanation: Executes specific code blocks based on a given condition.
Select Case Statements:
Syntax:
Select Case expression
Case value1
' Code to execute for value1
Case value2
' Code to execute for value2
Case Else
' Code to execute if no match is found
4)End Select
Explanation: Provides a way to execute different blocks of code based
on the value of an expression.
For Each Statements:
Syntax:
For Each element In collection
' Code to execute for each element in the collection
5)Next
Explanation: Iterates over each element in a collection, such as an array
or a list.
Do While/Do Until Statements:
Syntax:
Do While condition
' Code to execute while the condition is true
Loop
or
Do Until condition
' Code to execute until the condition is true
6)Loop
Explanation: Repeatedly executes a block of code while (or until) a
specified condition is true.
Try...Catch...Finally Statements:
Syntax:
Try
' Code that might cause an exception
Catch ex As Exception
' Code to handle the exception
Finally
' Code that always executes, whether an exception occurred or not
7)End Try
Explanation: Used for error handling. The code in the Try block is
monitored for exceptions, and if one occurs, the corresponding Catch
block is executed.
Exit Statements:
Syntax:
Exit For ' Exits a For loop
Exit While ' Exits a While loop
Exit Sub ' Exits a subroutine
Exit Function ' Exits a function
Explanation: Forces an immediate exit from a loop, subroutine, or
function.
8)Return Statements:
Syntax:
Return expression
Explanation: Exits a function and returns a value to the calling code.
class Program
{
static void Main()
{
// Input two numbers
Console.Write("Enter the first number: ");
double num1 = Convert.ToDouble(Console.ReadLine());
class Program
{
static void Main()
{
// Input the side length of the square
Console.Write("Enter the side length of the square: ");
double sideLength = Convert.ToDouble(Console.ReadLine());
' Wait for user input before closing the console window
Console.ReadLine()
End Sub
' Wait for user input before closing the console window
Console.ReadLine()
End Sub
End Module
' Wait for user input before closing the console window
Console.ReadLine()
End Sub
End Module
2)Password Input:
<input type="password">: Similar to a text input, but the entered text is
masked for security (useful for passwords).
3)Textarea:
<textarea></textarea>: Allows users to enter multiple lines of text.
4)Checkbox:
<input type="checkbox">: Represents a checkbox that users can check or
uncheck.
5)Radio Button:
<input type="radio">: Represents a radio button, part of a group of radio
buttons where only one can be selected at a time.
6)Select Dropdown:
<select><option></option></select>: Creates a dropdown list, allowing
users to select one option from a list.
7)Button:
<button></button>: Creates a clickable button.
8)Submit Button:
<input type="submit">: Submits the form data to the server.
9)Reset Button:
<input type="reset">: Resets the form to its default values.
10)Image Input:
<input type="image" src="image.jpg">: Uses an image as a submit button.
11)File Input:
<input type="file">: Allows users to upload files.
12)Hidden Input:
<input type="hidden">: Stores data on the form that is not displayed to the
user.
8)Handle Exceptions:
Use try-catch blocks to handle exceptions that may occur during database
operations. Proper error handling is crucial for robust database
connectivity.
Try
' Database operations
Catch ex As Exception
' Handle the exception
Finally
' Close the connection in the finally block to ensure it gets closed even if
an exception occurs
connection.Close()
End Try
9)Dispose of Resources:
Dispose of the connection object and other ADO.NET objects to release
resources explicitly.
connection.Dispose()
class Doctor
{
public string Name { get; set; }
public string Specialization { get; set; }
public Doctor(string name, string specialization)
{
Name = name;
Specialization = specialization;
}
}
class Program
{
static void Main()
{
// Create a list of doctors
List<Doctor> doctors = new List<Doctor>
{
new Doctor("Dr. John Smith", "Cardiologist"),
new Doctor("Dr. Lisa Johnson", "Orthopedic Surgeon"),
new Doctor("Dr. Emily Davis", "Neurologist"),
// Add more doctors as needed
};
class Program
{
static void Main()
{
Console.WriteLine("Prime numbers between 2 and 20:");
csharp
// Base class
public class Animal
{
public string Name { get; set; }
// Derived class
public class Dog : Animal
{
public void Bark()
{
Console.WriteLine("Dog is barking.");
}
}
Access Modifiers in Inheritance:
Public members of the base class are accessible in the derived class.
Protected members of the base class are accessible in the derived class.
Private members of the base class are not directly accessible in the
derived class.
Internal members are accessible if the derived class is in the same
assembly.
2)Overriding Methods:
Derived classes can provide their own implementation for a method
already defined in the base class using the override keyword.
csharp
public class Cat : Animal
{
public void Meow()
{
Console.WriteLine("Cat is meowing.");
}
csharp
public sealed class FinalClass
{
// Class implementation
}
2)Button:
<asp:Button>: Represents a button control that can initiate actions when
clicked.
3)Label:
<asp:Label>: Displays static text or can be used to display dynamic text
from the server side.
4)DropDownList:
<asp:DropDownList>: Represents a dropdown list for selecting items.
5)ListBox:
<asp:ListBox>: Represents a list box for selecting multiple items.
6)CheckBox:
<asp:CheckBox>: Represents a checkbox control.
7)RadioButton:
<asp:RadioButton>: Represents a radio button control.
8)Image:
<asp:Image>: Displays an image on the web page.
9)HyperLink:
<asp:HyperLink>: Represents a hyperlink control.
10)GridView:
<asp:GridView>: Represents a tabular data control for displaying data in
a grid.
11)Repeater:
<asp:Repeater>: Represents a data-bound control that can iterate over a
collection of data.
12)Calendar:
<asp:Calendar>: Represents a calendar control for selecting dates.
13)FileUpload:
<asp:FileUpload>: Allows users to upload files to the server.
14)LoginView:
<asp:LoginView>: Represents a control for displaying different content
to users based on their authentication status.
15)Validation Controls:
<asp:RequiredFieldValidator>, <asp:RegularExpressionValidator>, etc.:
Used for client-side and server-side validation of user input.
csharp
public class MyClass
{
// Default Constructor
public MyClass()
{
// Initialization code here
}
// Parameterized Constructor
public MyClass(int value)
{
// Initialization code with a parameter
}
}
Default Constructor: It has no parameters and is automatically called
when an object is instantiated.
Destructors:
Destructor is a special method that is used for cleaning up resources
before an object is destroyed or goes out of scope. In C#, a destructor is
defined using the ~ symbol followed by the class name and has no
parameters or return type. Unlike constructors, destructors are not
called explicitly; they are automatically invoked by the garbage collector.
csharp
public class MyClass
{
// Destructor
~MyClass()
{
// Cleanup code here
}
}
The destructor is called automatically when the garbage collector
determines that there are no references to the object.
It's important to note that in C#, you don't typically need to write
destructors explicitly unless your class manages unmanaged resources
(such as file handles or database connections).
Example:
csharp
using System;
public class MyClass
{
private string message;
// Parameterized Constructor
public MyClass(string msg)
{
message = msg;
Console.WriteLine("Constructor: " + message);
}
// Destructor
~MyClass()
{
Console.WriteLine("Destructor: " + message);
}
}
class Program
{
static void Main()
{
// Create an object and call the constructor
MyClass obj = new MyClass("Hello");