Windows Phone Developers

Tuesday, March 30, 2010

System.StackOverflowException was unhandled - Set Property C#

Set Property C# goes to infinite loop

If the set property goes to infinite loop, then there is some problem with accessor and mutator.

The following example is a good (rather bad) for recursive looping of the properties


public playerType PlayerType
{
get { return PlayerType; }

set
{
PlayerType = value;
}

}





In order to correct it, declare a private variable and get/set that variable.



private playerType _PlayerType;

public playerType PlayerType
{
get { return _PlayerType; }

set
{
_PlayerType = value;
}

}

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Monday, March 29, 2010

Your step-into request resulted in an automatic step-over of a property or operator.

Your step-into request resulted in an automatic step-over of a property or operator.

This behavior can be overridden in the context menu for the line being executed by choosing 'Step Into Specific' or by unchecking the option 'Step over properties and operators'.

Do you want to continue being notified when an automatic step-over happens?

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Sunday, March 28, 2010

How to effectively use #region in Visual Studio

#region lets you specify a block of code that you can expand or collapse when using the outlining feature of the Visual Studio Code Editor.

The collapse and expand feature can be used for advantage with good declaration of regions

For example:


namespace BlogExample_WinAppOne
{
class ClassTeam
{
#region declarations
public enum playerType { ClassA, ClassB, ClassC, Contract }
#endregion

#region properties
public playerType PlayerType
{
get { return PlayerType; }

set
{
PlayerType = value;
}

}


#endregion

#region public methods
public string SetPlayer
{

}
#endregion
}
}



Would look like the following when collapsed:




Please share your thoughts on effective usage of #region Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Invalid expression term '>'


Only assignment, call, increment, decrement, and new object expressions can be used as a statement

Invalid expression term '>'

The error is most likely for some VB programmer coding C#. The following snippet shows you why:

Wrong

if (value.Length <> 0)



Correct

if (value.Length != 0)

or

if (value.Length > 0)



VB Programmers tend to use <>:) Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Semicolon after method or accessor block is not valid

Semicolon after method or accessor block is not valid error is thrown when the semicolon is not appropriately placed.




For example


set { PlayerType = value };


should be


set { PlayerType = value; }


You can post your own examples for helping readers Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Saturday, March 27, 2010

Enumeration in C#

Here is a simple way to declare and use enumerations

Declaration is by using the enum keyword


public enum playerType { ClassA, ClassB, ClassC, Contract }



And you can use as shown below:


ClassTeam CT = new ClassTeam();
CT.PlayerType = ClassTeam.playerType.Contract;

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Partial Classes in C# (.NET)






Why to use Partial Classes?



Partial classes have many advantages. The most visible being the ability to split the class in multiple files. This is quite evident in Windows forms.


Windows forms has the class being split between two files - Form1.cs and FormDesigner.cs


Windows Forms application

partial class

Form1

{

///

/// Required designer variable.

///

private System.ComponentModel.IContainer components = null

;



And

public partial class

Form1 : Form

{

public

Form1()

{

check_whitespace();

InitializeComponent();

}

The same concept can be effectively used in the classes you create also.

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon