Senator Guerra Souty original series calendar,replica hublot blue steel peach pointer collocation of rolex replica Rome digital scale, track type minute replica watches scale shows that the classical model is swiss replica watches incomparable, wearing elegant dress highlights.


C# articles and tutorials

Read C# articles

Sort by:

<< Start < Prev 1 Next > End >>
Page 1 of 1

C# articles and tutorials

# articles: 3  

C# yield operator

View(s): 8813

C# yield operator

Prior to .NET 2.0, the only way you could create your own collection which could be traversed using the 'foreach' construct was by having you class implementing the IEnumerable and IEnumerator Interfaces.

However since .NET 2.0 we have a new operator called 'yield'. This allows your class to be iterated by its consumer but without the need to implement the above-mentioned interfaces.

Let us see a small example of how this works:

// Our class does not implement any interface !
public class School
    // Explicit initialization just for demo purposes !
    private string[] studentNames = {"John", "Joan","Joanne", "Tony", "Peter"};

    // The iterating method
    public IEnumerator GetEnumerator()
        foreach (string name in studentNames)
            // yield return in action !
            yield return name;

And now the code for the consumer:

class Program
    static void Main(string[] args)
        School NorthCoast = new School();
        // How School's internal collection was iterated is hidden to the user
        foreach (string student in NorthCoast)
(Continued...) View Full Aritlce

  Last updated on Wednesday, 02 April 2014
  Author: Mr. Ponna
4/5 stars (4 vote(s))

Creating Windows Services with Visual Studio 2008

View(s): 13996

Creating Windows Services with Visual Studio 2008

A Windows services is a application that runs in the background.  There is documentation on the Web for creating a Service with Visual Studio 2003, but is is changed for VS 2005, and 2008.

I will walk thru a sample Service in Visual Studio 2008.  This should also work with VS 2005.

Create the Service.

Description: Description: servicecreate

From Visual Studio Start Page, choose create project…   Select Windows Service and give it a name of NewService.

Description: Description: serviceblank

First thing we will do is add a timer to the Service.  DO NOT USE THE TIMER IN THE TOOLBOX.  The Timer for Windows Forms does not work for Services.  We will have to find the System.Timers.Timer component by right clicking on the Toolbox, and Choose Items.

Find the one that matches below:
Description: Description: servicetimerchoose

Click OK.  This will put the Timer into the Printing section of the Toolbar for some reason.

From The Service1 designer.  Click on Timer1, and set the interval to 10000 (10 Seconds).  Then Double-click to open Code View for Timer1_Elapsed.

Add the Following Code to the Timer1_Elapsed:

Dim MyLog As New EventLog() 
‘ create a new event log 
‘ Check if the the Event Log Exists

If Not 
MyLog.SourceExists(“NewService”) Then 
MyLog.CreateEventSource(“NewService”, “NewService_Log”) ‘ Create Log
End If 

MyLog.Source = “NewService” ‘ Write to the Log 
MyLog.WriteEntry(“NewService_Log”, “Service is Running” _ , EventLogEntryType.Information)

End Sub

And For OnStart():

Protected Overrides

(Continued...) View Full Aritlce

  Last updated on Friday, 21 February 2014
  Author: Mr. Ponna
2/5 stars (2 vote(s))

Understanding Object Lifetime

View(s): 30094

Understanding Object Lifetime

.NET objects are allocated in a memory called managed heap, where they will be automatically destroyed by the garbage collector.

Before going into details you have to know about the class, object, reference, stack and heap.

A class is nothing but a blueprint that describes how an instance of this type will look and feel in memory. Classes, of course, are defined within a code file (which in C# takes a *.cs extension).

Consider a simple Car class defined in a C# Console Application project named SimpleGC:

    public class Car
        private int currSp;
        private string petName;
        public Car() { }
        public Car(string name, int speed)
            petName = name;
            currSp = speed;

        public override string ToString()
            return string.Format("{0} is going {1} MPH",
            petName, currSp);

Once a class is defined, you can allocate any number of objects using the C# new keyword.

Understand, that the new keyword returns a reference to the

(Continued...) View Full Aritlce

  Last updated on Tuesday, 03 December 2013
  Author: Kishore Kumar
4/5 stars (15 vote(s))

<< Start < Prev 1 Next > End >>
Page 1 of 1
Register Login Ask Us Write to Us Help