Dotnet, DotnetCore, Azure, C#,VB.net, Sql Server, WCF, MVC ,Linq, Javascript and Jquery
24 November 2011
When to Use Structure?
When to Use Structure?
Do not define a structure unless the type has all of the following characteristics:
-It logically represents a single value, similar to primitive types (integer, double, and so on).
-It has an instance size smaller than 16 bytes.
-It is immutable[whose state cannot be modified after it is created].
-It will not have to be boxed frequently.
When to Use Delegates Instead of Interfaces ?
When to Use Delegates Instead of Interfaces ?
Both delegates and interfaces allow a class designer to separate type declarations and implementation. A given interface can be inherited and implemented by any class or struct;
A delegate can created for a method on any class
Use a delegate when:
-An eventing design pattern is used.
-It is desirable to encapsulate a static method.
-The caller has no need access other properties, methods, or interfaces on the object implementing the method.
-Easy composition is desired.
-A class may need more than one implementation of the method.
Use an interface when:
There are a group of related methods that may be called.
A class only needs one implementation of the method.
The class using the interface will want to cast that interface to other interface or class types.
The method being implemented is linked to the type or identity of the class: for example, comparison methods.
21 November 2011
When to Use Inheritance ?
When to Use Inheritance ?
Inheritance is a good choice when:
- Your inheritance hierarchy represents an "is-a" relationship and not a "has-a" relationship.
- You can reuse code from the base classes.
- You need to apply the same class and methods to different data types.
- The class hierarchy is reasonably shallow, and other developers are not likely to add many more levels.
- You want to make global changes to derived classes by changing a base class.
- Composition – Composition is used when the two class has-a relationship among classesInheritance – Inheritance is used when the derived class is-a relationship base classFor example :Take two class1.House owner2.HouseHouse owner is a House is not valid - InheritanceHouse owner has a house is valid - CompositionFor example :Take two class1.Game2.CricketCricket is a game is valid - InheritanceCricket has a game is invalid - Composition
14 November 2011
Empty all table values in the Database
Empty all table values in the Database
CREATE PROCEDURE SP_EmplyAllTableValues
AS
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
EXEC sp_MSForEachTable 'DELETE FROM ?'
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
GO
exec SP_EmplyAllTableValues
Stack and Queue Realtime example and System Example:
Stack and Queue Realtime example and System Example:
Queuing Example[FIFO]
System : Message Queue - MSMQ
Real Time:The bullet in a machine gun
Stack Example[LIFO]
System : Memory Allocation in System
Real Time:The tennis balls in their container
12 November 2011
File Creation Date and Time Conversion in C#
File Creation Date and Time Conversion in C#
using System;
using System.IO;
using System.Windows.Forms;
namespace ConvertDataTime
{
public partial class ConvertDataandTime : Form
{
public ConvertDataandTime()
{
InitializeComponent();
}
private void btnConvert_Click(object sender, EventArgs e)
{
try
{
//"08/26/2011 15:00:00"
FileSystemInfo f = new FileInfo(@txtPath.Text);
f.CreationTime = Convert.ToDateTime(txtDateTime.Text);
f.LastWriteTime = Convert.ToDateTime(txtDateTime.Text);
f.LastAccessTime = Convert.ToDateTime(txtDateTime.Text);
}
catch (Exception ex)
{
throw ex;
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
txtDateTime.Text = "08/26/2011 15:00:00";
txtPath.Text="D:\\";
}
}
}
11 November 2011
Composition vs Inheritance in OOPS
Composition vs Inheritance in OOPS
Composition – Composition is used when the two class has-a
relationship among classes
Inheritance – Inheritance is used when the derived class
is-a relationship base class
For example :
Take two class
1.House owner
2.House
House owner is a House is not valid - Inheritance
House owner has a house is valid - Composition
For example :
Take two class
1.Game
2.Cricket
Cricket is a game is valid - Inheritance
Cricket has a game is invalid - Composition
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; ...