Archive for the ‘C#’ Category

Types in .Net - Part 2

Wednesday, April 23rd, 2008

Types in .Net - Part 2

In a previous article “Types in .Net - Part 1“, we looked at Built In Value Types. In this part we will look at User Defined Value Types.

User Defined Value Types:
User Defined Value Types are called structs. ’struct’ is the keyword we use in C# to create them. You can define them just like a class as in:

public struct MyStruct
{
}

You cant inherit a struct. Structs are Value Types not reference types like classes ie they are created on the stack not on heap.

The other type of Value Type is enum. The following code shows how to define enum’s.


public enum MyEnum
{
Value1,
Value2,
Value3
}

Enum’s are actually Integers, but when you do a .ToString() on them you get the representation like “Value1″. Enums are useful when programming and when you have to force to pick up from a certain list of values.

You use enum as follows:

MyEnum myEnum = MyEnum.Value1;

In a later article we will take a look at Reference types, which would be the concluding article to this series.

Types in .Net - Part 2

Types in .Net - Part 1

Tuesday, April 22nd, 2008

Types in .Net - Part 1

There are primarily two types in .Net:
- Value types
- Reference types.

In this article we will be focusing on Value Types. All Numeric types, Boolean type, Character type etc.. are Value types. .Net framework 2.0 has more than 300 value types. We will be looking at only a few if them. The Numeric Types are used frequently so the C# language as well as VB.Net language provided aliases for them. The following is a partial list of the available Value types in .Net Framework 2.0.

- System.SByte
- System.Byte
- System.Int16
- System.Int32
- System.UInt32
- System.Int64
The above 6 Value types are used for Whole numbers.

- System.Single
- System.Double
- System.Decimal
The above 3 Value types are used for floating point numbers.

- System.Char
- System.Boolean

Value types have a implicit constructor so declaring them instantiates them, no need of using the ‘new’ keyword.

We will cover Nullable’s, User Defined Value Types and Enums in future articles.

Types in .Net - Part 1

TDD - Test Driven Development - An Introduction

Wednesday, April 2nd, 2008

TDD - Test Driven Development - An Introduction

TDD - Test Driven Development.
First of all what is TDD ? TDD is writing test cases while developing.

How is it important ?
You write the code, you write the test cases and see that all test cases pass. Now when you modify some code, you can just run these test cases and see that there are no breaking changes. Though time consuming, worth the time.

What tools do you have for .Net developers ??
Here is a list of free tools / tools which have a free version.
1) Moq - Moq is the only mocking library for .NET developed from scratch to take full advantage of .NET 3.5 (i.e. Linq expression trees) and C# 3.0 features (i.e. lambda expressions). It supports mocking interfaces as well as classes.

2) Rhino Mocks - Rhino Mocks’ purpose is to ease testing by allowing the developer to create mock implementations of custom objects and verify the interactions using unit testing.

3) MbUnit - Extensible unit testing framework that extends classic frameworks such as NUnit and csUnit by providing a variety of new specialized test fixtures. Developpers can even defined their own new fixtures.

4) NUnit - Unit-testing framework for all .NET languages.

5) White - Windows application automation. White supports rich client applications: Win32, Windows Forms and WPF.

6) Ranorex - Windows GUI test and automation library.

7) Watin - WatiN (Web Application Testing In .NET) allows you to automate Web application testing with Internet Explorer.

8) TestDriven.Net - Unit testing add-in for Visual Studio .NET.

9) xUnit.net - Unit testing framework.

This may not be a complete list, If I missed something please let me know through comments. Out of this list I would prefer NUnit and MbUnit.

In a future articles I will go over TDD in more detail.

TDD - Test Driven Development - An Introduction

DynAjax

Tuesday, February 19th, 2008

DynAjax

DynAjax is a framework for AJAX, no controls like in anthem etc… Just get the JSON or whatever you return from your method and use it in your javascript.

Website

Update
I received this comment from the DynAjax webmaster, I thought I will post his comment directly in the post. The following is the comment that he posted:

I’m the DynAjax webmaster, thank you for this post.

I just wanted to add some more informations about it:
- each method you want to access from the JavaScript side must be declared into an XML configuration file, then you can easily call it as you were in C# code.
- security in DynAjax: many Ajax frameworks don’t bother about security and let any client access data from server side. DynAjax implements a way to check user authentication before any method call, it works like a firewall on client requests.
- enhancements: a lot of new features will arrive soon (Exception trapping management, annotations on C# code, partial javascript generation etc.)

Samples available here:
http://samples.dynajax.org/

Regards,
Benoit BEGUIN

DynAjax

FastSharp - Another Code Snippet Compiler

Tuesday, February 12th, 2008

FastSharp - Another Code Snippet Compiler

I posted about Snippet Compiler a nice little handy tool. Here is another similar tool worth checking out.

FastSharp is a text editor which lets you compile and run C# code that would normally exist inside a method.

Download the Source Code and Binaries here.

FastSharp - Another Code Snippet Compiler


Books 24x7