tagged [static-methods]

Static method in a generic class?

Static method in a generic class? In Java, I'd like to have something as: But I get I don't understand generics beyond the basic uses and thus can't make much sense of that. It doesn't help that I was...

3 Apr at 18:30

Static methods - How to call a method from another method?

Static methods - How to call a method from another method? When I have regular methods for calling another method in a class, I have to do this but when I have static methods I can't write

8 Feb at 14:13

Is there any benefit (semantic or other) to using a static method that calls a constructor?

Is there any benefit (semantic or other) to using a static method that calls a constructor? I just updated Visual Studio 2013 and I noticed that in the project template for an MVC application the Appl...

20 Jun at 01:49

HttpContext.Current.Response inside a static method

HttpContext.Current.Response inside a static method I have the following static method inside a static class. My question is it safe to use HttpContext.Current.Response inside a static method? I want ...

13 Nov at 09:36

What is the use of the static modifier in object-oriented programming?

What is the use of the static modifier in object-oriented programming? In one of my interviews, I was asked what the `static` modifier signifies. I replied by telling the interviewer that static class...

Should C# methods that *can* be static be static?

Should C# methods that *can* be static be static? Should C# methods that be static be static? We were discussing this today and I'm kind of on the fence. Imagine you have a long method that you refact...

19 Dec at 16:10

Variable sharing inside static method

Variable sharing inside static method I have a question about the variables inside the static method. Do the variables inside the static method share the same memory location or would they have separa...

8 Nov at 18:50

calling another method from the main method in java

calling another method from the main method in java I have but then when I call `do()` from `main` by running the command `java foo` on the command line, java complains that you can't call a method fr...

How can I run a static initializer method in C# before the Main() method?

How can I run a static initializer method in C# before the Main() method? Given a static class with an initializer method: How can I ensure the initializer is run before `Main()`? The best I can think...

Does a static method share its local variables & what happens during concurrent usage from different threads?

Does a static method share its local variables & what happens during concurrent usage from different threads? C# Question - I'm trying to determine whether it is OK to use a static method where, withi...

13 Aug at 03:10

Threading and static methods in C#

Threading and static methods in C# Here is a meaningless extension method as an example: Say a thread of execution completes upto and including the line: The processor then context switches and anothe...

What is the difference between static methods in a Non static class and static methods in a static class?

What is the difference between static methods in a Non static class and static methods in a static class? I have two classes Class A and ClassB: I want to know what is the differenc

C# Static variables - scope and persistence

C# Static variables - scope and persistence I just did a little experiment: and then I ran: ``` MessageBox.Show(MyClass.Foo().ToString()); M

13 May at 00:31

Is there a way to force a C# class to implement certain static functions?

Is there a way to force a C# class to implement certain static functions? I am developing a set of classes . A consumer of my library shall expect each of these classes to implement a certain set of s...

24 Feb at 08:11

Class with single method -- best approach?

Class with single method -- best approach? Say I have a class that's meant to perform a single function. After performing the function, it can be destroyed. Is there any reason to prefer one of these ...

9 Mar at 05:18

Static method containing object instances, is it wrong?

Static method containing object instances, is it wrong? I'm using an extension method for class. Within that extension method I create an instance of StringBuilder. Here is the code: ``` public static...

30 Oct at 14:45

How do I know if this C# method is thread safe?

How do I know if this C# method is thread safe? I'm working on creating a call back function for an ASP.NET cache item removal event. The documentation says I should call a method on an object or call...

How can I force inheriting classes to implement a static method in C#?

How can I force inheriting classes to implement a static method in C#? All I want to do is that child classes of the class implement a method and I want this to be checked at compile time to avoid run...

15 Dec at 08:51

Calling a Static method in C#

Calling a Static method in C# How do I call a static method? I want to call this from a class I have created, I want to get the location from IP. I've declared it but what I need to do is call the met...

21 Jun at 21:38

How to verify static void method has been called with power mockito

How to verify static void method has been called with power mockito I am using the following. Here is my utils class here is gist of the class under test: ``` public class InternalService { public

"Expected class, delegate, enum, interface or struct" error on public static string MyFunc(). What's an alternative to "string"?

"Expected class, delegate, enum, interface or struct" error on public static string MyFunc(). What's an alternative to "string"? I'm getting an error when I attempt to use the following static functio...

14 May at 13:26

C# class instance with static method vs static class memory usage

C# class instance with static method vs static class memory usage How does C#, or other languages for that matter, handle memory allocation (and memory de-allocation) between these two scenarios: 1.) ...

27 Feb at 19:18

Why would I use static methods for database access

Why would I use static methods for database access So I came across this issues today and I couldn't find some meaningful explanation is there some non-subjective reason to use static methods when it ...

28 Jan at 18:23

Hangfire DistributedLockTimeoutException when calling the same static method concurrently

Hangfire DistributedLockTimeoutException when calling the same static method concurrently I have a web service that, when posted to, queues up downloads of images in Hangfire, so that if the image dow...

19 Jan at 08:13