Click here to Skip to main content
15,891,033 members
Home / Discussions / C#
   

C#

 
GeneralRe: autocomplete inside a datagrid Pin
pcflasch20-Sep-06 3:33
pcflasch20-Sep-06 3:33 
QuestionBuilding unused methods in a class Pin
Nadia Monalisa19-Sep-06 9:04
Nadia Monalisa19-Sep-06 9:04 
AnswerRe: Building unused methods in a class Pin
Dave Kreskowiak19-Sep-06 9:29
mveDave Kreskowiak19-Sep-06 9:29 
GeneralRe: Building unused methods in a class Pin
Nadia Monalisa19-Sep-06 10:42
Nadia Monalisa19-Sep-06 10:42 
GeneralRe: Building unused methods in a class Pin
Dave Kreskowiak19-Sep-06 11:50
mveDave Kreskowiak19-Sep-06 11:50 
GeneralRe: Building unused methods in a class Pin
Nadia Monalisa19-Sep-06 14:53
Nadia Monalisa19-Sep-06 14:53 
QuestionWhen to choose Static Method/Variables rather than Instance Method/Variable Pin
Nadia Monalisa19-Sep-06 8:55
Nadia Monalisa19-Sep-06 8:55 
AnswerRe: When to choose Static Method/Variables rather than Instance Method/Variable Pin
Dave Kreskowiak19-Sep-06 10:03
mveDave Kreskowiak19-Sep-06 10:03 
They have nothing to do with threading at all. It comes down to data encapsulation.

If you look at the FileInfo and File classes in the System.Io namespace, you'll see that they do the exact same things, only in slightly different ways. FileInfo is an instance implementation and File is static.

You can copy a file either of two ways. You can create an instance of a FileInfo object, then call the .CopyTo() method on it, passing in just the destination file name since the object already knows that it is the source path.
FileInfo myFile = new FileInfo("C:\\Test.txt");
myFile.CopyTo("D:\\TEST\\Test.txt");

Or you can use the static methods exposed by the File class, where you have to specify both the source and the destination paths:
File.Copy("C:\\Test.txt", "D:\\TEST\\Test.txt");

The FileInfo class encapsulates a single file where you can get properties on that file and tell it to delete, copy, or move itself. All of the methods will only work on that instance of the class.

The File class doesn't encapsulate anything. It requires you to specify which file it's going to work on with every single call you make.

You can read more about it here[^]. 'Cause if most of what you're writing is static methods, you're completely missing the point of object-oriented programming.


Dave Kreskowiak
Microsoft MVP - Visual Basic


AnswerRe: When to choose Static Method/Variables rather than Instance Method/Variable Pin
Guffa19-Sep-06 10:35
Guffa19-Sep-06 10:35 
GeneralRe: When to choose Static Method/Variables rather than Instance Method/Variable Pin
Nadia Monalisa19-Sep-06 10:48
Nadia Monalisa19-Sep-06 10:48 
GeneralRe: When to choose Static Method/Variables rather than Instance Method/Variable Pin
Christian Graus19-Sep-06 13:19
protectorChristian Graus19-Sep-06 13:19 
GeneralRe: When to choose Static Method/Variables rather than Instance Method/Variable Pin
Nadia Monalisa19-Sep-06 14:38
Nadia Monalisa19-Sep-06 14:38 
GeneralRe: When to choose Static Method/Variables rather than Instance Method/Variable Pin
Christian Graus19-Sep-06 14:47
protectorChristian Graus19-Sep-06 14:47 
GeneralRe: When to choose Static Method/Variables rather than Instance Method/Variable Pin
Nadia Monalisa19-Sep-06 16:25
Nadia Monalisa19-Sep-06 16:25 
GeneralRe: When to choose Static Method/Variables rather than Instance Method/Variable Pin
Christian Graus19-Sep-06 16:40
protectorChristian Graus19-Sep-06 16:40 
GeneralRe: When to choose Static Method/Variables rather than Instance Method/Variable Pin
Nadia Monalisa19-Sep-06 17:30
Nadia Monalisa19-Sep-06 17:30 
GeneralRe: When to choose Static Method/Variables rather than Instance Method/Variable Pin
Nadia Monalisa2-Oct-06 4:32
Nadia Monalisa2-Oct-06 4:32 
QuestionLeft Function in C# Pin
MyRunner2319-Sep-06 7:34
MyRunner2319-Sep-06 7:34 
AnswerRe: Left Function in C# Pin
Jon Sagara19-Sep-06 7:41
Jon Sagara19-Sep-06 7:41 
AnswerRe: Left Function in C# Pin
Eric Dahlvang19-Sep-06 7:45
Eric Dahlvang19-Sep-06 7:45 
GeneralRe: Left Function in C# Pin
samtam19-Sep-06 22:13
samtam19-Sep-06 22:13 
GeneralRe: Left Function in C# Pin
Eric Dahlvang20-Sep-06 4:33
Eric Dahlvang20-Sep-06 4:33 
GeneralRe: Left Function in C# Pin
samtam20-Sep-06 20:26
samtam20-Sep-06 20:26 
QuestionHow to capture the URL? Pin
zhoujun19-Sep-06 5:11
zhoujun19-Sep-06 5:11 
QuestionCalculating scientific notation? Pin
Goalie3519-Sep-06 5:10
Goalie3519-Sep-06 5:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.