Dotnet, DotnetCore, Azure, C#,VB.net, Sql Server, WCF, MVC ,Linq, Javascript and Jquery
8 September 2012
Difference between Sleep and Hibernate in Laptops?
Difference between Sleep and Hibernate in Laptops?
-Sleep is a power-saving state that allows a computer to quickly resume full-power operation, Sleep puts your work and settings in memory and draws a small amount of power.
-Hibernation is also a power-saving state designed primarily for laptops. It puts your open documents
and programs on your hard disk and then turn off your computer.
Off all the power-saving states in Windows, hibernate uses the least amount of power.
If you won't use your laptop for an extended period and won't have an opportunity to charge the battery during that time - Hibernate is most efficient one.
21 August 2012
SQL SERVER – Query to Find Seed Values, Increment Values and Current Identity Column value of a table
SQL SERVER – Query to Find Seed Values, Increment
Values and Current Identity Column value of a table
SELECT IDENT_SEED(TABLE_NAME) AS Seed,
IDENT_INCR(TABLE_NAME) AS Increment,
IDENT_CURRENT(TABLE_NAME) AS Current_Identity,
TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE OBJECTPROPERTY(OBJECT_ID(TABLE_NAME), 'TableHasIdentity') = 1
AND TABLE_TYPE = 'BASE TABLE' and
TABLE_NAME='MSubject' -- [Table name]
For all the table in Database:
SELECT IDENT_SEED(TABLE_NAME) AS Seed,
IDENT_INCR(TABLE_NAME) AS Increment,
IDENT_CURRENT(TABLE_NAME) AS Current_Identity,
TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE OBJECTPROPERTY(OBJECT_ID(TABLE_NAME), 'TableHasIdentity') = 1
AND TABLE_TYPE = 'BASE TABLE'
7 August 2012
Lamda expression in C#
Lamda expression in C#
A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types.
All lambda expressions use the lambda operator =>, which is read as "goes to".
The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. The lambda expression x => x * x is read "x goes to x times x."
This expression can be assigned to a delegate type as follows:
To create an expression tree type:
A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types.
All lambda expressions use the lambda operator =>, which is read as "goes to".
The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. The lambda expression x => x * x is read "x goes to x times x."
This expression can be assigned to a delegate type as follows:
delegate int del(int i); static void Main(string[] args) { del myDelegate = x => x * x; int j = myDelegate(5); //j = 25 }
To create an expression tree type:
using System.Linq.Expressions; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Expression myET = x = > gt; x * x;
}
}
}
The =>; operator has the same precedence as assignment (=) and is right-associative.Lambdas are used in method-based LINQ queries as arguments to standard query operator methods such as Where.
6 August 2012
Anonymous Types in C#
Anonymous Types in C#
Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first.
The following example shows an anonymous type that is initialized with two properties named Amount and Message.
var v = new { Amount = 108, Message = "Hello" }; // Rest the mouse pointer over v.Amount and v.Message in the following // statement to verify that their inferred types are int and string. Console.WriteLine(v.Amount + v.Message);
In the following example, the names of the properties of the anonymous type are Color and Price.
var productQuery = from prod in products select new { prod.Color, prod.Price }; foreach (var v in productQuery) { Console.WriteLine("Color={0}, Price={1}", v.Color, v.Price); }
11 July 2012
String vs string in c#
String vs string in C#
we use either the keyword string or String .
Is both String and string same in C# ?
string is just an alias name for the class System.String which means both has the same functionality.
The IL code generated for both of them is also same .
Note that string is a keyword , but String isn’t which lets you create an variable with the name String like
Another interesting thing is we can also declare variable name as String
String String = "Arun Prakash";
MessageBox.Show(String);
If you declare the variable name as string, Error occured
String string = " Arun Prakash";
MessageBox.Show(string);
Is both String and string same in C# ?
string is just an alias name for the class System.String which means both has the same functionality.
The IL code generated for both of them is also same .
Note that string is a keyword , but String isn’t which lets you create an variable with the name String like
Another interesting thing is we can also declare variable name as String
String String = "Arun Prakash";
MessageBox.Show(String);
If you declare the variable name as string, Error occured
String string = " Arun Prakash";
MessageBox.Show(string);
Use of Using Statement in C#
Use of Using Statement in C#
In C#, using Keyword is used in two different ways and are hence referred to differently.
As a Directive
In this usage, the "using" keyword can be used to include a namespace in your program. (Mostly used)
In this usage, the "using" keyword can be used to include a namespace in your program. (Mostly used)
As a Statement
Using can also be used in a block of code to dispose an IDisposable objects.
Using can also be used in a block of code to dispose an IDisposable objects.
SqlConnection connection = new SqlConnection("connection string");
SqlCommand cmd = new SqlCommand("SELECT * FROM SomeTable", connection);
SqlDataReader reader = cmd.ExecuteReader();
connection.Open();
if (reader != null)
{
while (reader.Read())
{
//do something
}
}
reader.Close(); // close the reader
connection.Close(); // close the connection
|
If any exception occurs inside while block it throws exception, the connection.close() process will not executed due to the exception. To avoid this situation, we can take the help of the try....catch... finally block by closing the connection inside the finally block or inside the catch block.
Advantages of the below code:
"Using" keyword takes the parameter of type IDisposable. Whenever you are using any IDisposable type
object you should use the "using" keyword to handle automatically when it should close or dispose.
Internally using keyword calls the Dispose() method to dispose the IDisposable object.
using (SqlConnection connection = new SqlConnection("connection string"))
{
connection.Open();
using (SqlCommand cmd = new SqlCommand("SELECT * FROM SomeTable", connection))
{
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader != null)
{
while (reader.Read())
{
//do something
}
}
} // reader closed and disposed up here
} // command disposed here
} //connection closed and disposed here
|
7 July 2012
Cloud Computing
Cloud Computing
Cloud computing is the delivery of computing and storage capacity [1] as a service [2] to a heterogeneous community of end-recipients. The name comes from the use of a cloud-shaped symbol[3] as an abstraction for the complex infrastructure it contains in system diagrams[4]. Cloud computing entrusts services with a user's data, software and computation over a network.
There are three types of cloud computing:[5]
- Infrastructure as a Service (IaaS),
- Platform as a Service (PaaS), and
- Software as a Service (SaaS).
Using Infrastructure as a Service, users rent use of servers (as many as needed during the rental period) provided by one or more cloud providers.
Using Platform as a Service, users rent use of servers and the system software to use in them.
Using Software as a Service, users also rent application software and databases. The cloud providers manage the infrastructure and platforms on which the applications run.
End users access cloud-based applications through a web browser or a light-weight desktop or mobile app while the business software and user's data are stored on servers at a remote location.
Proponents claim that cloud computing allows enterprises to get their applications up and running faster, with improved manageability and less maintenance, and enables IT to more rapidly adjust resources to meet fluctuating and unpredictable business demand.
Cloud computing relies on sharing of resources to achieve coherence and economies of scale similar to a utility (like theelectricity grid) over a network (typically the Internet). At the foundation of cloud computing is the broader concept of converged infrastructure and shared services.
Subscribe to:
Posts (Atom)
Implementing OAuth validation in a Web API
I mplementing OAuth validation in a Web API Implementing OAuth validation in a Web API using C# typically involves several key steps to sec...
-
ViewBag, ViewData, TempData and View State in MVC ASP.NET MVC offers us three options ViewData, ViewBag and TempData for passing data from...
-
// Export Datatable to Excel in C# Windows application using System; using System.Data; using System.IO; using System.Windows.Forms; ...