Click here to Skip to main content
15,895,011 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Non static class with only static methods Pin
Gregory Gadow4-Mar-11 4:08
Gregory Gadow4-Mar-11 4:08 
GeneralRe: Non static class with only static methods Pin
PIEBALDconsult4-Mar-11 10:17
mvePIEBALDconsult4-Mar-11 10:17 
AnswerRe: Non static class with only static methods Pin
Bernhard Hiller2-Mar-11 3:01
Bernhard Hiller2-Mar-11 3:01 
AnswerRe: Non static class with only static methods Pin
Gregory Gadow4-Mar-11 4:06
Gregory Gadow4-Mar-11 4:06 
GeneralRe: Non static class with only static methods Pin
Karthik. A4-Mar-11 4:16
Karthik. A4-Mar-11 4:16 
GeneralRe: Non static class with only static methods Pin
Gregory Gadow4-Mar-11 6:53
Gregory Gadow4-Mar-11 6:53 
GeneralRe: Non static class with only static methods Pin
Karthik. A4-Mar-11 7:54
Karthik. A4-Mar-11 7:54 
AnswerRe: Non static class with only static methods Pin
Karthik. A4-Mar-11 4:14
Karthik. A4-Mar-11 4:14 
You could use static methods if the functionality of the method is not dependent on the instance properties/methods. Consider the following class as an example. There is a static "Parse" method that takes in a string and return a new instance of "Data". This static function "does not" depend on any of the instance properties/methods of the Data class. But it just creates an instance of the Data class for you to use. So, any other class that wishes to create an instance of Data (which has a ',' seperated int's) can do so by calling Data.Parse(_stringValue).

public class Data
{
    private List<int> a;

    public Data()
    {
      a = new List<int>();
    }

    public Data(int[] nums)
    {
       a = new List<int>();
       // add to a
    }

    public static Data Parse(string nums)
    {
       // say nums = "1,2,3
       string[] _nums = nums.Split(",".ToCharArray());
       List<int> iList = new List<int>();
       foreach(string s in nums)
          iList.Add(int32.Parse(s));
       return new Data(iList.ToArray());
    }
}


PS - This is a just a trivial example of the usage of static methods in a non-static class.

Edit - If there are only static methods in a non-static, it might be useless, but it could also be for futuristic reasons. They could add to this class more instance properties / methods in the future that would use these static methods.
Cheers,
Karthik

QuestionUrl Image Path in WPF Pin
Pranit Kothari1-Mar-11 8:03
Pranit Kothari1-Mar-11 8:03 
AnswerRe: Url Image Path in WPF Pin
Pete O'Hanlon1-Mar-11 8:54
mvePete O'Hanlon1-Mar-11 8:54 
AnswerRe: Url Image Path in WPF Pin
Pete O'Hanlon1-Mar-11 9:25
mvePete O'Hanlon1-Mar-11 9:25 
QuestionNot able to see my yesterday's question and replies Pin
sr15928-Feb-11 19:46
sr15928-Feb-11 19:46 
AnswerRe: Not able to see my yesterday's question and replies Pin
RobCroll28-Feb-11 21:45
RobCroll28-Feb-11 21:45 
AnswerRe: Not able to see my yesterday's question and replies Pin
Eddy Vluggen28-Feb-11 23:09
professionalEddy Vluggen28-Feb-11 23:09 
AnswerRe: Not able to see my yesterday's question and replies Pin
Abhinav S1-Mar-11 1:02
Abhinav S1-Mar-11 1:02 
QuestionAdding layers Pin
Sander Rossel25-Feb-11 8:19
professionalSander Rossel25-Feb-11 8:19 
AnswerRe: Adding layers Pin
Not Active25-Feb-11 10:23
mentorNot Active25-Feb-11 10:23 
GeneralRe: Adding layers Pin
Sander Rossel25-Feb-11 12:44
professionalSander Rossel25-Feb-11 12:44 
GeneralRe: Adding layers Pin
Not Active25-Feb-11 13:43
mentorNot Active25-Feb-11 13:43 
GeneralRe: Adding layers Pin
Sander Rossel25-Feb-11 22:20
professionalSander Rossel25-Feb-11 22:20 
GeneralRe: Adding layers Pin
jschell26-Feb-11 13:49
jschell26-Feb-11 13:49 
AnswerRe: Adding layers Pin
Eddy Vluggen25-Feb-11 23:02
professionalEddy Vluggen25-Feb-11 23:02 
GeneralRe: Adding layers Pin
Sander Rossel26-Feb-11 1:03
professionalSander Rossel26-Feb-11 1:03 
GeneralRe: Adding layers Pin
Eddy Vluggen26-Feb-11 6:01
professionalEddy Vluggen26-Feb-11 6:01 
AnswerRe: Adding layers Pin
Richard MacCutchan25-Feb-11 23:13
mveRichard MacCutchan25-Feb-11 23:13 

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.