How do i make a class that MUST be instantiated [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
how do I make a class that MUST be instantiated it, or anything like that. If it is possible anyway..

You can just make a class with no static members, you know. You must instantiate a class with no static members in order to use its functionalities. Although it still inherits from Object's static members. But if you want to remove that as well, I am sorry but it is impossible.

Related

why is Read7BitEncodedInt(); in BinaryReader protected? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I know you can easily create a wrapper around BinaryReader and expose Read7BitEncodedInt
But I'm just curious why the creators chose to not make it public
Is there a logic reason for it?
My guess is that this is internal implementation detail and isn't required to effectively use the BinaryReader. I wonder the opposite, why isn't it private? Presumably, there is a subclass out there that needs to use it or overwrite the implementation...

When to use abstract class over an interface with default implementations? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
C# 8 adds the option for default method implementation in interfaces, meaning a method CAN be defined in the interface.
In a situation when I DON'T need a default constructor, nor inherited fields in the derived classes, what should I default to: An interface with a default implementation, or the old-school way of an abstract class?
Is there a convention for styling for this case?

Define constants needed in more than one class [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
In my smart client solution, I have a Project folder with:
IProjectView.cs
*ProjectView*
ProjectView.cs
ProjectView.Designer.cs
ProjectView.GeneratedCode.cs
ProjectView.resx
ProjectViewPresenter.cs
I want to define some constants for user by ProjectView.cs and ProjectViewPresenter.cs. Both of these classes implement IProjectView.cs, so were I back in Java, I'd put them there. If this were C++, I'd create a class ProjectConstants.cs and have the classes inherit it, but C# doesn't allow multiple inheritance.
How do I do this?
Can having a Read-Only Property in your interface solve your problem?
string MyReadOnlyProperty { get; }
I have no clue if this is very performance-wise compared to constant thought.

Your own " Timer.Interval" [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a question about c#, but I have no idea how to google it or something. So I''m going to ask it here:
In c#, you have things like "Timer.Interval". Is it possible to make something similair like that myself?
For example, I have this void called "writeLine". I have this boolean, UseDelay, so that my function waits a while before writing things down. I want that boolean to become accessible as "writeLine.UseDelay = false" or "if (writeLine.UseDelay == false)" etc. I'm just curious.
Thanks in advance!
What you're talking about is actually a Property of a class. There are ofcourse ways you can implement your own properties (actually just public variables inside the structure of your class) and your own methods (for example, take a look here). If you're interested in further constructions and options, there is plenty of information on the web.

Should a class that provides functionality be static or singelton? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm writing a C# app, and I have a class that all it dos is to provide functionality to different class I use.
For example a class that provides clock service and more.
is there any reason to make that class a Singelton class? or Static class?
Or maybe it should not be either?
If your class needs to keep an inner state it should be a Singelton, if it doesn't simply make it static!
Inner states could be:
A file reference
A user preference
Any kind of history
If it is merely a collection of functions etc.. like Math, KISS (keep it simply Static)!

Categories

Resources