Hi All,
Can you please help me any body regarding this. I have folder in "D:\\files" have number of files are there in this drive, i want every day at 5 pm zip the first 10 files by using windows services
Can you please provide related some liks .
Advanced Thanks,
Regards,
Narasimha
Loading

Bechir BejaouiPosted Dec 24, 2008, 8:52 AM
Ok good, you tel me this is an excelent theoric response but how and what for do I use a static constructor instead of the instance one?
Imagine this real situation, you have an icon on your desktop that represent an application, if you click the icon then the application will start, if you click 10000 the icon then 10000 instance of you application will start without any need, then how do we do to prevent that? the response is implementing the singleton pattern and using a static constructor
public class Application
{
private Application() { }
static private Application()
{
/*TO DO: implement this inorder to perform
some tasks when the application is started
* for the first time or leave it empty
*/
}
static public Application CreateInstance()
{
return new Application();
}
}
If you implement this above code only one instance will be started even if you start clicking the application icon from now to tomorrow!!!
to call the application you will use the static method that called also the class method CreateInstance() and it is called class method because it is called through the class and not through instance of the class
Application x = new Application();
x ->(point)-> then you will find nothing in the intellisense after the point that indicates the CreateInstance()
but if you try
Application->(point)->then you will find the CreateInstance in the intellisense
The static members are called class members because they are reached through the class it self and not the instance of the class and they are not accessible through instance member
imagine within a class you have static int counter;
and
public void addToCounter()
{
//the counter will not appear in the intellisense because it is not accessible
// throough this instance method
}
Now imagin this code
public class Person
{
static public int MadPersons;
public string FirstName;
public string LastName;
static public void AddNewMadPerson()
{
++ MadPersons;
}
}
if you want to count the Mad persons within your class person then you have to define it as above
A little remark:
it is worth to put static before any other keyword when you're defining a static member,I mean static public bla bla bla instead of public static bla bla bla like the rest of developer do.
Niradhip ChakrabortyPosted Dec 24, 2008, 7:23 AM
static constructor:
http://www.c-sharpcorner.com/UploadFile/cupadhyay/StaticConstructors11092005061428AM/StaticConstructors.aspx
static variable :
A static variable is a variable that will be the same in all instances of a class.
Normally each class as its own copy of all variables. If you declare some as static, then they will have the same value in each instance of a class.
Here's a small program that should allow you to easily see what's going on:
using System;
class confuse
{
static int i;
static confuse()
{
i=6;
i++;
}
public void stc()
{
Console.WriteLine("The value of i= {0}",i);
}
public void stc1()
{
i++;
Console.WriteLine("The value of i= {0}",i);
}
public static void Main()
{
confuse obj=new confuse();
obj.stc();
confuse obj1=new confuse();
obj1.stc1();
}
}