h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

FxCop and StyleCop

It runs on compiled DLLs.
As it runs on compiled IL code, it can be used for C#, VB.NET, in short any language which compiles to IL code.
StyleCop
Keep in mind that it is not a Microsoft product. It is not even a Team System Power Tool. It is a tool developed by a very passionate developer at Microsoft (on evenings and weekends). There's no support, servicing, evolution or anything else beyond what he can get done in his spare time. Style checking is an interesting feature and may show up in an official product at some point down the road.
It runs on actual source code.
Currently it runs only on C#.
The ultimate goal of StyleCop is to allow to produce elegant, consistent code that team members and others who view developer code will find highly readable.
Code Analysis
No spell checking - FxCop uses a dictionary (plus custom dictionary) to check the names of methods, classes, etc. Code Analysis doesn't seem to do that.
Help - FxCop not only complained when something was wrong but provided a great deal of help/hints to resolve the problem. Code Analysis just seems to present the problem with no sign of a hint.
Note that Code Analysis is only available in the Premium and Ultimate editions of Visual Studio 2010 and also Visual Studio 2005 & 2008 Team System.

FxCop analyzes programming elements in managed assemblies, called targets, and provides an informational report that contains messages about the targets, Messages include suggestions about how to improve the source code used to generate them. FxCop represents the checks it performs during an analysis as rules. A rule is managed code that can analyze targets and return a message about its findings. Rule messages identify any relevant programming and design issues and, when possible, supply information about how to fix the target.
Using FxCop, you can perform the following tasks:
Control which rules are applied to targets.
Exclude a rule message from future reports.
Apply style sheets to FxCop reports.
Filter and save messages.
Save and reuse application settings in FxCop projects.
Working in the FxCop Application Window
The FxCop application window displays the targets and rules included in a project, and the messages that are generated when an analysis is performed. The window is divided into three major areas: the configuration pane on the left, the messages pane on the right, and the properties pane at the bottom.

Define Usage of Lock Keyword in C#

                      The lock keyword may be useful especially when you are using threading in your application. It ensures that only one thread can enter and use the critical section. If another thread needs to use the critical section, it has to wait until the previous object is released.

Application.Run in C#.Net

  • The Application.Run will run the standard application message loop in the current thread where the Application runs.
  • The Application.Run also takes the parameter of type Form

Descendants vs. Elements in Linq to XML

Starting with Elements(XName).
Returns a filtered collection of the child elements of this element or document, in document order.
Only elements that have a matching XName are included in the collection.
And secondly the Descendants(XName) method.
Returns a filtered collection of the descendant elements for this document or element, in document order.
Only elements that have a matching XName are included in the collection.

Use Proper Casing for Members

IdentifierCasingExample
Class, StructPascalStrategyManager
InterfacePascal with I prefixIStrategy
EnumerationPascalLoggingLevel
Enumeration ValuePascalInfo
Enumeration Representing Bit FieldPascal in plural SearchOptions
EventPascalClick
Private FieldCamel with underscore_scheduler
Protected FieldCamel with underscore _scheduler
Constant FieldPascalPi
Constant VariableCameldefinitionKey
Readonly FieldCamel with underscore_listItems
Static Readonly FieldPascalListValues
VariableCamelvalue
MethodPascalComputeValue
PropertyPascalValue
ParameterCamelparameter
Type ParameterPascal with T prefixTValue
NamespacePascalSystem.Drawing
Abbreviation with 2 and less lettersAll Caps UI, IO
Abbreviation with 3 and more lettersPascal Xml, Http
Use Proper Class Layout
Use the following order to position all your members inside the class. The resulting layout is the combination of all the lists provided with descending priority. That means that on the top of the file there will be all public const fields followed by internal const fields.
1.     Fields
2.     Delegates
3.     Events
4.     Properties
5.     Indexers
6.     Constructors
7.     Finalizers
8.     Methods
9.     Other stuff
Than follow access modifier.
1.     public
2.     internal
3.     protected
4.     private
After access modifier follow the type of the member.
1.     const
2.     static
3.     readonly
4.     nothing
The least significant sorting attribute is a declaration modifier.
1.     virtual
2.     abstract
3.     override
4.     new

XSLT Elements

                     The links in the "Element" column point to attributes and more useful information about each specific element.


Element
Description
Applies a template rule from an imported style sheet
Applies a template rule to the current element or to the current element's child nodes
Adds an attribute
Defines a named set of attributes
Calls a named template
Used in conjunction with <when> and <otherwise> to express multiple conditional tests
Creates a comment node in the result tree
Creates a copy of the current node (without child nodes and attributes)
Creates a copy of the current node (with child nodes and attributes)
Defines the characters and symbols to be used when converting numbers into strings, with the format-number() function
Creates an element node in the output document
Specifies an alternate code to run if the processor does not support an XSLT element
Loops through each node in a specified node set
Contains a template that will be applied only if a specified condition is true
Imports the contents of one style sheet into another. Note: An imported style sheet has lower precedence than the importing style sheet
Includes the contents of one style sheet into another. Note: An included style sheet has the same precedence as the including style sheet
Declares a named key that can be used in the style sheet with the key() function
Writes a message to the output (used to report errors)
Replaces a namespace in the style sheet to a different namespace in the output
Determines the integer position of the current node and formats a number
Specifies a default action for the <choose> element
Defines the format of the output document
Declares a local or global parameter
Defines the elements for which white space should be preserved
Writes a processing instruction to the output
Sorts the output
Defines the elements for which white space should be removed
Defines the root element of a style sheet
Rules to apply when a specified node is matched
Writes literal text to the output
Defines the root element of a style sheet
Extracts the value of a selected node
Declares a local or global variable
Specifies an action for the <choose> element
Defines the value of a parameter to be passed into a template

Define Lambda Expression

Lambda Expression is a function without a name the calculates and returns single value.
Lambda Expression uses to lambda operator => [Goes To].
Syntax:
Inut Parameter) => Expression
Example:
Add Two TestBox into Form.
TxtInput and TxtOutput.
string[] arrName ={"Lakshmi",,"Narayaanan","Sriram","Suresh","Sravan","Srinath"};

Convert int? to int in C#.net

Convert int? to int in C#.net
int? v1;
int v2;
if(v1.HasValue)
v2=v1.Value

App Config File in C#.net

Read Setting Method
public static string ReadSetting(string key)
{
return ConfigurationSettings.AppSettings[key];
}
Write Setting Method
public static void WriteSetting(string key, string value)
{
XmlDocument doc = LoadConfigDocument();
XmlNode node = doc.SelectSingleNode("//appSettings");
if (node == null)
throw new InvalidOperationException("appSettings section not found in config file.");
try
{
XmlElement elem = (XmlElement)node.SelectSingleNode(string.Format("//add[@key='{0}']", key));
if (elem != null)
{
elem.SetAttribute("value", value);
}
else
{
elem = doc.CreateElement("add");
elem.SetAttribute("key", key);
elem.SetAttribute("value", value);
node.AppendChild(elem);
}
doc.Save(GetConfigFilePath());
}
catch
{
throw;
}
}
Remove Setting Method
public static void RemoveSetting(string key)
{
XmlDocument doc = LoadConfigDocument();
XmlNode node = doc.SelectSingleNode("//appSettings");
try
{
if (node == null)
throw new InvalidOperationException("appSettings section not found in config file.");
else
{
node.RemoveChild(node.SelectSingleNode(string.Format("//add[@key='{0}']", key)));
doc.Save(GetConfigFilePath());
}
}
catch (NullReferenceException e)
{
throw new Exception(string.Format("The key {0} does not exist.", key), e);
}
}
Load Config Document Method
private static XmlDocument LoadConfigDocument()
{
XmlDocument doc = null;
try
{
doc = new XmlDocument();
doc.Load(GetConfigFilePath());
return doc;
}
catch (System.IO.FileNotFoundException e)
{ throw new Exception("No configuration file found.", e);
}
}
Get Config FilePath Method
private static string GetConfigFilePath()
{
return Assembly.GetExecutingAssembly().Location + ".config";
}


Display ODD or Even using LINQ in C#.net

This is the C# Code for Find display Odd or Even Number using LINQ .
var numbers = from n in Enumerable.Range(1,25)
select new {number = n,OddEven =n %2 ==1? "odd","Even"};
foreach(var n in mubers)
{
listbox1.items.add("The Number is" ,+n.number +n.OddEven);
}