Coding Standards for C#: Names
Why Coding Standards
Simple: maintainability. If, 6 months down the line, your customer isn't too happy with the product and wants an enhancement in the application you have created, you should be able to do it without introducing new bugs. There are a lot of other good reasons, but this is the one which concerns us more than anything else.
Not following any standard is like going with a temporary solution (which might lead to a permanent problem) and, as you will see, it takes less effort to keep in mind a few simple measures than to do haphazard coding.
All you have to do is study good standards once and keep them in the back of your head. Trust me; it's worth it.
Contents
1. Naming - What is meant by meaningful names
2. Casing - When to use PascalCase and when camelCase
4. Generics - Proper usage
5. Delegates - Proper usage
6. Miscellaneous - Some short tidbits
7. Common Pitfalls - Mistakes we should watch out for
8. References - Where to get more information
Naming
"The beginning of wisdom is to call things by their right names" - Chinese Proverb
"Meaningful" is the keyword in naming. By meaningful names, I mean concise names that accurately describe the variable, method or object. Let's see how this would be in C#:
Namespaces - Names should be meaningful and complete. Indicate your company or name, product and then your utility. Do not abbreviate.
//Good
namespace CompanyName.ProductName.Utility
//Bad
namespace CN.PROD.UTILClasses - Class names should always be a noun and, again, should be meaningful. Avoid verbs
//Good
class Image
{
...
}
class Filters
{
...
}
//Bad
class Act
{
...
}
class Enhance
{
...
}Methods - Always use a verb-noun pair, unless the method operates on its containing class, in which case, use just a verb.
//Good
public void InitializePath();
public void GetPath();
public void ShowChanges();
public void System.Windows.Forms.Form.Show();
//Bad
public void Path();
public void Changes();Methods with return values - The name should reflect the return value.
//Good
public int GetImageWidth(Bitmap image);
//Bad
public int GetDimensions(Bitmap image);Variables - Do not abbreviate variable names. Variable names should again be descriptive and meaningful.
//Good
int customerCount = 0;
int index = 0;
string temp = "";
//Bad
int cc = 0;
int i = 0;
string t = "";Private member variables - Prefix class member variables with
m_.public class Image
{
private int m_initialWidth;
private string m_filename;
...
}Interfaces - Prefix all interface names with
I. Use a name that reflects an interface's capabilities, either a general noun or an "-able".interface IClock
{
DateTime Time { get; set; }
...
}
interface IAlarmClock : IClock
{
void Ring();
DateTime AlarmTime { get; set; }
...
}
interface IDisposable
{
void Dispose();
}
interface IEnumerable
{
IEnumerator GetEnumerator();
}Custom attributes - Suffix all attribute class names with
Attribute. The C# compiler recognizes this and allows you to omit it when using it.public class IsTestedAttribute : Attribute
{
public override string ToString()
{
return "Is Tested";
}
}
//"Attribute" suffix can be omitted
[IsTested]
public void Ring();Custom exceptions - Suffix all custom exception names with
Exception.public class UserNotExistentException :
System.ApplicationException
{
...
}Delegates - Suffix all event handlers with
Handler; suffix everything else withDelegate.public delegate void ImageChangedHandler();
public delegate string StringMethodDelegate();
Casing
C# standards dictate that you use a certain pattern of Pascal Casing (first word capitalized) and Camel Casing (all but first word capitalized).
Pascal Casing - use PascalCasing for classes, types, methods and constants.public class ImageClass
{
const int MaxImageWidth = 100;
public void ResizeImage();
}
enum Days
{
Sunday,
Monday,
Tuesday,
...
}
Camel Casing - use camelCasing for local variables and method arguments.int ResizeImage(int imageCount)
{
for(int index = 0; index < imageCount; index++)
{
...
}
}
Generics
Generics, introduced in .NET 2.0, are classes that work uniformly on values of different types.
Use capital letters for types; don't use "Type" as a suffix.
//Good
public class Stack ‹T›
//Bad
public class Stack ‹t›
public class Stack ‹Type›
Delegates
Use delegate inference instead of explicit delegate instantiation.
public delegate void ImageChangedDelegate();
public void ChangeImage()
{
...
}
//Good
ImageChangedDelegate imageChanged = ChangeImage;
//Bad
ImageChangedDelegate imageChanged =
new ImageChangedDelegate(ChangeImage);Use empty parenthesis on anonymous methods without parameters.
public delegate void ImageChangeDelegate();
ImageChangedDelegate imageChanged = delegate()
{
...
}
Miscellaneous
- Avoid putting
usingstatements inside a namespace - Check spelling in comments
- Always start left curly brace { on a new line
- Group framework namespaces together; add custom and thirdparty namespaces below
- Use strict indentation (3 or 4 spaces, no tabs)
- Avoid fully qualified type names
- Indent comment at the same line as the code
- All member variables should be declared at the top of classes; properties and methods should be separated by one line each
- Declare local variables as close as possible to the first time they're used
- File names should reflect the classes that they contain
Common Pitfalls
Let's face it, we all do these things one time or another. Let's avoid them as best as we can:
Names that make sense to no one but ourselves.
string myVar;
MyFunction();Single or double letter variable names (this is excusable for local variables).
int a, b, c, a1, j1, i, j, k, ii, jj, kk, etc.Abstract names.
private void DoThis();
Routine48();
string ZimboVariable;Acronyms.
//AcronymFunction
AF();
//SuperFastAcronymFunction
SFAT()Different functions with similar names.
DoThis();
DoThisWillYa();Names starting with underscores. They look cool, but let's not ;)
int _m1 = 0;
string __m2 = "";
string _TempVariable = "";Variable names with subtle and context-less meanings.
string asterix = "";
// (this is the best function of all)
void God()
{
...
}Abbreviations.
string num;
int abr;
int i;
References
- Coding Standard: C#
- How to Write Unmaintainable Code
- C# Coding Style Guide
- Juval Lowy - IDesign.NET
- Edited by reinux (thanks rei)
Shared by DeepWaters
Labels: Coding, CSharpTricks, Technology
Monday, April 30, 2007
Tree Data structure in C Sharp .NET
Here is a simple Tree data structure in C sharp.NET
using System;
using System.Collections.Generic;
using System.Text;
namespace Algorithms
{
class Tree
{
private TreeNode root;
public Tree()
{
root = null;
}
public TreeNode FindRecursive(TreeNode root, int dataValue)
{
if (root == null)
{ return null; }
else if (root.DataValue == dataValue)
{ return root; }
else if (root.DataValue < dataValue)
{ return FindRecursive(root.RightNode, dataValue);}
else
{ return FindRecursive(root.LeftNode, dataValue);
}
}
public TreeNode Find(int dataValue)
{
if (root == null)
{
return null;
}
else
{
TreeNode currentNode = root;
while (currentNode != null)
{
if (currentNode.DataValue == dataValue)
{
return currentNode;
}
else if (currentNode.DataValue < dataValue)
{
currentNode = currentNode.RightNode;
}
else if (currentNode.DataValue > dataValue)
{
currentNode = currentNode.LeftNode;
}
return null;
}
return null;
}
}
}
public class TreeNode
{
private int dataValue;
private TreeNode leftNode = null;
private TreeNode rightNode = null;
public TreeNode(int data)
{
dataValue = data;
}
public TreeNode LeftNode
{
get
{
return leftNode;
}
set
{
leftNode = value;
}
}
public TreeNode RightNode
{
get
{
return rightNode;
}
set
{
rightNode = value;
}
}
public int DataValue
{
get
{
return dataValue;
}
set
{
dataValue = value;
}
}
}
}
Labels: CSharpTricks, DataStructures
Sunday, March 25, 2007
Check If Cycle exists in a Linked List
Check if the linked list contains a cycle
using System;
using System.Collections.Generic;
using System.Text;
namespace Algorithms
{
public class LinkedList
{
private Node head;
public LinkedList()
{
head = null;
}
public bool CheckCycle()
{
Node step1Node = head;
Node step2Node = head.NextNode;
while (true)
{
if ((step2Node == null)||(step2Node.NextNode == null))
return false;
else if ((step1Node.Equals(step2Node))||(step1Node.Equals(step2Node.NextNode)))
return true;
else
{
step2Node = step2Node.NextNode;
step2Node = step2Node.NextNode;
step1Node = step1Node.NextNode;
}
}
}
public int FindPosition(int data)
{
Node checkNode = head;
int position = 1;
int dataPosition = 0;
while (checkNode != null)
{
if (checkNode.DataValue == data)
{
dataPosition = position;
}
checkNode = checkNode.NextNode;
position = position + 1;
}
return dataPosition;
}
}
public class Node
{
private int dataValue;
private Node nextNode = null;
public Node(int data)
{
dataValue = data;
}
public Node NextNode
{
get
{
return nextNode;
}
set
{
nextNode = value;
}
}
public int DataValue
{
get
{
return dataValue;
}
set
{
dataValue = value;
}
}
}
}
Labels: CSharpTricks, DataStructures
Sunday, February 25, 2007
Nth Element from the last in a Linked List
Another advanced algorithm is to find the Nth Element from the LAST with the optimal performance.Here is the implementation
using System;
using System.Collections.Generic;
using System.Text;
namespace Algorithms
{
public class LinkedList
{
private Node head;
public LinkedList()
{
head = null;
}
public int FindNthElementFromLast(int m)
{
int n = m - 1;
int returnValue = -1;
if (n >= 0)
{
Node nthElement = head;
Node currentElement = head;
for (int i =0;i less than n;i++)
{
if (currentElement.NextNode != null)
{
currentElement = currentElement.NextNode;
}
else
{
returnValue = -1;
return returnValue;
}
}
if (returnValue != -1)
{
while (currentElement.NextNode != null)
{
currentElement = currentElement.NextNode;
nthElement = nthElement.NextNode;
}
returnValue = nthElement.DataValue;
}
}
return returnValue;
}
}
public class Node
{
private int dataValue;
private Node nextNode = null;
public Node(int data)
{
dataValue = data;
}
public Node NextNode
{
get
{
return nextNode;
}
set
{
nextNode = value;
}
}
public int DataValue
{
get
{
return dataValue;
}
set
{
dataValue = value;
}
}
}
}
Labels: CSharpTricks, DataStructures
Linked List SORT Algorithm
If you need a sort algorithm in Linked List. Please check other implementation in my last blog.
using System;
using System.Collections.Generic;
using System.Text;
namespace Algorithms
{
public class LinkedList
{
private Node head;
public LinkedList()
{
head = null;
}
public void Sort()
{
if (head != null)
{
int j = 0;
Node MinElement = head;
Node currentElement = MinElement.NextNode;
while (currentElement != null)
{
if (currentElement.DataValue < MinElement.DataValue)
{
MinElement = currentElement;
Insert(MinElement.DataValue);
DeleteAtPosition(j+1);
}
MinElement = MinElement.NextNode;
}
}
}
}
public class Node
{
private int dataValue;
private Node nextNode = null;
public Node(int data)
{
dataValue = data;
}
public Node NextNode
{
get
{
return nextNode;
}
set
{
nextNode = value;
}
}
public int DataValue
{
get
{
return dataValue;
}
set
{
dataValue = value;
}
}
}
}
Labels: CSharpTricks, DataStructures
Linked List in C Sharp.NET
I got tones of emails, lately for Linklist and Tree data structure implemetationHere is a simple Linked List Data structure in C Sharp.NET. A LinkedList will always have two class a LinkedList class and a Node Class.
I have also included most common options to insert and Delete nodes.
using System;
using System.Collections.Generic;
using System.Text;
namespace Algorithms
{
public class LinkedList
{
private Node head;
public LinkedList()
{
head = null;
}
public void Insert(int dataValue)
{
if (head == null)
{
Node nodeInsert = new Node(dataValue);
head = nodeInsert;
nodeInsert.NextNode = null;
}
else
{
Node nodeInsert = new Node(dataValue);
nodeInsert.NextNode = head;
head = nodeInsert;
}
}
public void InsertAtPosition(Node insertNode, int i)
{
if (i == 0)
{
insertNode.NextNode = head;
head = insertNode;
}
else
{
Node currentNode = head;
Node currentNodeNext = head.NextNode;
for (int j = 0; j < i; j++)
{
currentNode = currentNode.NextNode;
currentNodeNext = currentNode.NextNode;
}
if (currentNode != null)
{
currentNode.NextNode = insertNode;
insertNode.NextNode = currentNodeNext;
}
}
}
public void DeleteAtPosition(int i)
{
if (i == 0)
{
head = null;
}
else
{
Node currentNode = head;
Node currentNodeNext = head.NextNode;
for (int j = 0; j < i; j++)
{
currentNode = currentNode.NextNode;
currentNodeNext = currentNode.NextNode;
}
if (currentNode != null)
{
currentNode.NextNode = currentNodeNext.NextNode;
}
}
}
public bool Delete(Node nodeToDelete)
{
bool returnFlag = false;
if (head == null)
returnFlag = false;
else if (head.Equals(nodeToDelete))
{
head = null;
returnFlag = true;
}
else
{
Node checkNode = head;
Node checkNodeNext = head.NextNode;
while (checkNodeNext != null)
{
if (checkNodeNext.Equals(nodeToDelete))
{
checkNode.NextNode = checkNodeNext.NextNode;
checkNodeNext = null;
returnFlag = true;
}
}
}
return returnFlag;
}
public void Print()
{
Node firstNode = head;
while (firstNode != null)
{
Console.Write(firstNode.DataValue + " ");
firstNode = firstNode.NextNode;
}
}
public void Clear()
{
Node checkNode = head;
Node checkNodeNext;
while (checkNode != null)
{
checkNodeNext = checkNode.NextNode;
checkNode = null;
checkNode = checkNodeNext;
}
}
}
public class Node
{
private int dataValue;
private Node nextNode = null;
public Node(int data)
{
dataValue = data;
}
public Node NextNode
{
get
{
return nextNode;
}
set
{
nextNode = value;
}
}
public int DataValue
{
get
{
return dataValue;
}
set
{
dataValue = value;
}
}
}
}
Labels: CSharpTricks, DataStructures
Saturday, January 20, 2007
First Non-Repeated Character from a UNICODE String using Hash Table
the only difference here is the input string can be UNICODE (65000 characters) instead of ASCII Code (256 characters) so using a hash table makes more sense
public static char FirstNonRepeatedHash(string stringToCheck)
{
Hashtable cHash = new Hashtable();
int length = stringToCheck.Length;
int i = 0;
bool hashPresent = false;
char charToReturn = '\0';
for (i = 0; i < length; i++)
{
hashPresent = cHash.Contains(stringToCheck[i]);
if (hashPresent)
{
cHash[stringToCheck[i]] = 1 + Convert.ToInt32(cHash[stringToCheck[i]]);
}
else
{
cHash.Add(Convert.ToChar(stringToCheck[i]), 1);
}
}
for (i = 0; i < length; i++)
{
if (Convert.ToInt32(cHash[stringToCheck[i]]) ==1 )
{
charToReturn = stringToCheck[i];
break;
}
}
return charToReturn;
}
Labels: CSharpTricks, String Manipulation
Monday, December 25, 2006
First Non repeated Character in a String using an Array
Here is how to find the first non repeated character in an a string using an arraythe assumption is the String is ASCII other wise check for the hash table function
For example If the input is "TEETOTALAR" The First non repeated Character is "O"
public static char FirstNonRepeatedArray(string stringToCheck)
{
int length = stringToCheck.Length;
int i = 0;
int[] intCollection = new int[256];
char returnChar = '\0';
for (i = 0; i < length; i++)
{
intCollection[stringToCheck[i]] = intCollection[stringToCheck[i]] + 1;
}
for (i = 0; i < length; i++)
{
if (intCollection[stringToCheck[i]] == 1)
{
returnChar = stringToCheck[i];
break;
}
}
return returnChar;
}
Labels: CSharpTricks, String Manipulation
String is a Palindrome !
How to check if a string is a palindrome ?You can change the code a bit to reverse an array
public static bool IsPalindrome(string s)
{
int length =s.Length;
char[] chrArray = s.ToCharArray();
if (length == 0)
return false;
if (length == 1)
return true;
int start = 0;
int end = length - 1;
while (end > start)
{
if (chrArray[start] == chrArray[end])
{
start++;
end--;
}
else
{
return false;
}
}
return true;
}
Labels: CSharpTricks, String Manipulation
Saturday, November 25, 2006
Remove Characters from a String with limited Memory
How about, If we don't have enough memory we have to use a single array.Here is how to do that with limited memory
public static string RemoveCharactersLimited(char[] s, string removeChars)
{
int i = 0, j = 0;
int lengthC = removeChars.Length;
int lengthS = s.Length;
int[] intCollection = new int[256];
for (i = 0; i < lengthC; i++)
{
intCollection[removeChars[i]] = 1;
}
i = j = 0;
for (i = 0; i < lengthS; i++)
{
if (intCollection[s[i]] != 1)
{
s[j] = s[i];
j++;
}
}
while (j < lengthS)
{
s[j] = '\0';
j++;
}
return new string(s);
}
Labels: CSharpTricks, String Manipulation
Wednesday, October 25, 2006
Remove Characters from String C#.NET
The string manipulation function removes a set of characters fromthe input stringFor example
Removing "RT" from "ROBERT FROST" will give you "OBE FOS"
public static string RemoveCharacters(string s, string removeChars)
{
int i=0,j=0;
int lengthC = removeChars.Length;
int lengthS = s.Length;
int[] intCollection = new int[256];
char[] s2 = new char[lengthS];
for (i = 0; i < lengthC; i++)
{
intCollection[removeChars[i]] = 1;
}
i = j = 0;
for (i = 0; i < lengthS; i++)
{
if (intCollection[s[i]] != 1)
{
s2[j] = s[i];
j++;
}
}
return new string(s2);
}
Labels: CSharpTricks, String Manipulation
AtoI function - String to Integer in C# .NET
If you ever want to convert a string to integer, you have to go through the following checks
public static int StringToInt(string s)
{
int length = s.Length;
int i = 0;
int lastNumber = 0;
int returnNumber = 0;
bool numberNegative = false;
int startPoint = 0;
if (s[0] == '-')
{
numberNegative = true;
startPoint = 1;
}
for (i = startPoint; i < length; i++)
{
if (s[i] == ' ')
{
continue;
}
else
{
if ((s[i] >= '0') && s[i] <= '9')
{
returnNumber = s[i] - '0';
if (i > 0) lastNumber = lastNumber * 10;
lastNumber = lastNumber + returnNumber;
}
else
{
break;
}
}
}
if (numberNegative)
lastNumber = -1 * lastNumber;
return lastNumber;
}
Labels: CSharpTricks, String Manipulation
Monday, September 25, 2006
Reverse Words in C Sharp.NET
Lately I started some string manipulation in C Sharp, which you will see in the series to come. Please add your comments suggestions. These are optimized for performanceInput: Robert Frost
output is Frost Robert
public static string ReverseWord(string s)
{
int length = s.Length;
int i = 0;
string[] splittedArray = s.Split(' ');
StringBuilder sb = new StringBuilder();
for (i = splittedArray.Length - 1; i >= 0; i--)
{
if (i != 0)
sb.Append(splittedArray[i] + ' ');
else
sb.Append(splittedArray[i]);
}
return sb.ToString();
}
Here is another method to do the same using character array
public static string ReverseWordChar(string s)
{
int length = s.Length;
int i = 0,j=0;
StringBuilder sb= new StringBuilder();
int startPos = length - 1;
for (i = length-1; i >=0;i--)
{
if (s[i] == ' ')
{
for (j = i+1; j <= startPos; j++)
{
sb.Append(s[j]);
}
startPos = i;
sb.Append(' ');
}
}
for (j = 0; j < startPos; j++)
{
sb.Append(s[j]);
}
return sb.ToString();
}
Labels: CSharpTricks, String Manipulation
Sunday, August 20, 2006
Factorial of a number using C #
Finding the factorial of a number in C#the code is meant for finding the factorial both recursive and non recursive
public static int Factorial(int n)
{
int FactorialValue = 1;
for (int i = n; i > 0; i--)
{
FactorialValue = FactorialValue * i;
}
return FactorialValue;
}
public static int recursiveFactorial(int n)
{
if (n > 1)
{
return n * recursiveFactorial(n - 1);
}
else
{
return 1;
}
}
public static int recursiveFactorialIntermediate(int n, int[] nArray)
{
if (n > 1)
{
nArray[n - 1] = n * recursiveFactorialIntermediate(n - 1, nArray);
return nArray[n - 1];
}
else
{
return 1;
}
}
Labels: CSharpTricks, Maths
Tuesday, July 25, 2006
largest element in the array by comparing to All - C#
To find out the largest element in the array by comparing to All elements methodThis methd has an Big Oh notation performance of O(n2)
public static int GetIndexLargestCompareToAll(int[] numbers)
{
int currentMaxIndex = -1;
int length = numbers.Length;
bool isMax = false;
try
{
if (length == 0)
currentMaxIndex = -1;
else if (length == 1)
currentMaxIndex = 0;
else
{
for (int i = 0; i < length; i++)
{
isMax = true;
for (int j = 0; j < length; j++)
{
if (numbers[j] > numbers[i])
isMax = false;
}
if (isMax)
currentMaxIndex = i;
}
}
}
catch (Exception)
{
currentMaxIndex = -1;
}
return currentMaxIndex;
}
Labels: CSharpTricks, DataStructures, Technology
Sunday, June 25, 2006
Largest Element in the Array using C #
To find out the largest element in the array by comparing to the Max methodThis methd has an Big Oh notation performance of O(n)
public static int GetIndexLargestCompareToMax(int[] numbers)
{
int currentMaxIndex = -1;
int length = numbers.Length;
try
{
if (length == 0)
currentMaxIndex = -1;
else if (length == 1)
currentMaxIndex = 0;
else
{
currentMaxIndex = 0;
for (int j = 1; j < length; j++)
{
if (numbers[j] > numbers[currentMaxIndex])
{
currentMaxIndex = j;
}
}
}
}
catch (Exception)
{
currentMaxIndex = -1;
}
return currentMaxIndex;
}
Labels: CSharpTricks, DataStructures
Calendar Object in C Sharp.NET
A friend of mine asked me to create a calendar object in C Sharp. I thought it might be useful to others tooSo here is a one for you
using System;
using System.Collections.Generic;
using System.Text;
namespace Algorithms
{
public class Calendar
{
private DateTime currentDate;
private int currentDay;
private int currentDayWeek;
private int currentMonth;
private int currentYear;
private bool leapYear;
public Calendar()
{
DateTime cDate = DateTime.Now;
currentDate = cDate;
currentDay = cDate.Day;
currentDayWeek = Convert.ToInt32(cDate.DayOfWeek);
currentMonth = cDate.Month;
currentYear = cDate.Year;
}
public Calendar(DateTime cDate)
{
currentDate = cDate;
currentDay = cDate.Day;
currentDayWeek = Convert.ToInt32(cDate.DayOfWeek);
currentMonth = cDate.Month;
currentYear = cDate.Year;
if (currentYear % 400==0)
leapYear = true;
else if (currentYear % 100==0)
leapYear = false;
else if (currentYear % 4==0)
leapYear = true;
else
leapYear = false;
}
public DateTime CurrentDate
{
get { return currentDate; }
set { currentDate = value;}
}
public int CurrentDay
{
get { return currentDay; }
set { currentDay = value; }
}
public int CurrentDayWeek
{
get { return currentDayWeek; }
set { currentDayWeek = value; }
}
public int CurrentMonth
{
get { return currentMonth; }
set { currentMonth = value; }
}
public int CurrentYear
{
get { return currentYear; }
set { currentYear= value; }
}
public bool LeapYear
{
get { return leapYear; }
}
public void Display()
{
Console.Write("== Calendar ==\n");
DateTime firstDay = currentDate.AddDays(1 - currentDay);
string dayDisplay ="";
if (Convert.ToInt32(firstDay.DayOfWeek) == 0)
{
dayDisplay = "Mo Tu We Th Fr Sa Su";
}
else if (Convert.ToInt32(firstDay.DayOfWeek) == 1)
{
dayDisplay = "Tu We Th Fr Sa Su Mo";
}
else if (Convert.ToInt32(firstDay.DayOfWeek) == 2)
{
dayDisplay = "We Th Fr Sa Su Mo Tu";
}
else if (Convert.ToInt32(firstDay.DayOfWeek) == 3)
{
dayDisplay = "Th Fr Sa Su Mo Tu We";
}
else if (Convert.ToInt32(firstDay.DayOfWeek) == 4)
{
dayDisplay = "Fr Sa Su Mo Tu We Th";
}
else if (Convert.ToInt32(firstDay.DayOfWeek) == 5)
{
dayDisplay = "Sa Su Mo Tu We Th Fr";
}
else if (Convert.ToInt32(firstDay.DayOfWeek) == 6)
{
dayDisplay = "Su Mo Tu We Th Fr Sa";
}
Console.Write(dayDisplay + "\n");
// Common content
Console.Write("01 02 03 04 05 06 07\n");
Console.Write("08 09 10 11 12 13 14\n");
Console.Write("15 16 17 18 19 20 21\n");
Console.Write("22 23 24 25 26 27 28\n");
//Variable Date
// Feb 2
if (currentMonth == 2)
{
if (leapYear)// Feb 2 leap year
Console.Write("29 00 00 00 00 00 00\n");
else
Console.Write("00 00 00 00 00 00 00\n");
}
if ((currentMonth == 4) || (currentMonth == 6) || (currentMonth == 9) || (currentMonth == 11))
{
// 4, 6, 9, 11
Console.Write("29 30 00 00 00 00 00\n");
}
if ((currentMonth == 1) || (currentMonth == 3) || (currentMonth == 5) || (currentMonth == 7) || (currentMonth == 8) || (currentMonth == 10) || (currentMonth == 12))
{
// 1,3,5,7,8,10,12
Console.Write("29 30 31 00 00 00 00\n");
}
}
}
}
Labels: CSharpTricks, Technology
Thursday, May 25, 2006
LEARN Your Way to MCAD Excellence
If you want to learn all about the .Net Windows, Web, and Xml Web Services and also get an MCAD certification as bonus.The following tips have helped me and 10's of my friends.
I will recommend THESE and ONLY THESE books in the FOLLOWING ORDER
The ORDER of the exam is also VERY IMPORTANT and it should be
1. Windows
2. Web
3. XML Web services
For each exam FIRST you must study completely the MS Press book (100%) and THEN AND ONLY THEN study Amit Kalani's one.
All the best !"
Amazon Link LEARN Your Way to MCAD Excellence
Labels: CSharpTricks
Thursday, April 27, 2006
C Sharp Tricks - First Post
In this website you will find tips, tricks, gotchas and some recipes for windows as well as web applications. This site is intended to share some of the things I've developed, some source code, articles and some samples I've wrote. Please leave your comments to improve. Thanks and I hope you will find them as useful as i do - Rajesh Lal.Along with C sharp you will also find the way it interacts with the related technologies.
- Windows Vista
- ASP.Net
- Microsoft SQL Server
- Javascript, AJAX, Atlas
- Web 2.0 , CSS
- Installation / deployment / orca
- Mobile devices etc
- C# foundation - data structures etc
Labels: CSharpTricks, News, Technology

