Creating classes [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
This might seem like a very trivial question to more experienced c# developers but please keep in mind I'am a beginner to the c# language but getting through it very well.
However I have came to a stumbling block regarding creating c# classes. I understand the whole concept of the intrinsic details on how to create the class i.e class is like a blueprint in which you create objects from in which there data is stored in fields in which you use constructors to initialize them (or default) and behaviours are performed in the form of methods bla bla etc etc.
However the question that I have is in regards to the purpose of creating your own classes in c#. I was wondering if we create our own classes like the ones that are available in the .net framework, I.e if the .Net framework hasn't got a class that wee need, so do wee then just create our own class defining the functionality that I need.
Is this the only purpose of creating classes or is this way more focused on creating DLL's, and I am missing something ?
Any ideas tips hints or expansions would be great (in laymen's Terms).

if the .Net framework hasn't got a class that wee need, so do wee then just create our own class defining the functionality that I need.
Yes.

Related

Modify method logic MOQ [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am new to unit testing so my questions might seem basic, apologies for that.
I am trying to figure out if there is such API in MOQ that can help me to modify a method logic.
I mean,
When calling . I want to increase lets say my "count" variable by 1 and then call the method or do something else, doesn't really matter.
There is no code yet, this is a principle question. Could not find it in the MOQ Documentation on GitHub.
Hope I was clear and you can help me with that.
Thank you!
You can't 'modify' the method logic per se, but you can replace it entirely.
When you create a mock of an interface, you aren't instantiating a specific concrete type of that interface. Instead, you are allowing your mocking framework to create a 'mock' version of that interface; an object which, by default, has no functionality but requires no work to instantiate.
The easiest way to do this is to use Moq's Setup functionality, which is explained well here:
https://github.com/Moq/moq4/wiki/Quickstart

Can I know how the language interoperability works in .NET with the help of example? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I was reading about the .NET framework and I read that ".NET provides language interoperability", and I also read the answer to the question What is language interoperability (basic concept) in .net framework?, but I don't have any idea about how to use this feature practically.
Create a simple project using C#, make a simple class and compile it. You will generate a .dll.
Then create a project using VB and import/include the one you compiled where you used C#. VB won´t take care of your C# code, but it can manage the class you created.
How? Because .NET is compiled in a common language. Does not matter if you have used C# or VB to generate the code.
Interoperability is a framework feature. Is rare that you need make use of this for small projects so I undestand you don't find a real way to carry out. But it is that simple as all what you do with C# in .NET you can reuse if you decide code in VB in the future or for some parts of a project.
In practice programmers decide to code in one language. But reusability is already there.
Feel free to ask what you need.
https://stackoverflow.com/a/43417187/7733724

C# Windows Application: handle large code in one form application with multiple tabs [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 6 years ago.
Improve this question
I'm going to develop a C# windows application which hosts several tabs in one form. Since components inside each tab are complicated enough, having all codes stored in one file Form1.cs is make it hard to handle all methods and code snippets.
I want to know are there any good practices to manage code in such condition?
I have made Forms Applications like that before, and I know what you mean about the code getting cumbersome for the .cs file.
Assuming you're not doing this already:
What I would do is compartmentalize some of the methods and members to separate classes that you call when needed via access operators and/or references. If you find yourself reusing the same set of lines dozens of times, put it in a static method that you can call everywhere without having to declare class objects... Each Tab can call some kind of method like RunTab1(); that will access the appropriate objects, classes, members and so forth. This way, when you want to work on Tab2, you can go to that class and ruffle through there, instead of going through one GIANT file looking for one small thing.
I know that sounds like a bit of a generic answer, but I've done it and it worked for me for a multilingual translator among many other things. Even what I'm working on now - some of the files are over 30k lines and I don't get any lag at runtime. Hope that helps.

Is ok to include the interface declaration of the class in the same file? [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 9 years ago.
Improve this question
due to unit-testing we create for every class an Interface. The .Net Framework coding standards say that every class, interface, enum, etc. should be located in a different file.
As these interfaces are so closely related with the class we were thinking of creating an internal coding-standards rule to put together the class and the interface.
Have you seen this approach before? What do you think about it?
PD: Always talking about interfaces used only to mock the classes, not 'real' interfaces that can have more than one implementation.
You should follow .NET coding standards and separate the interfaces into their own files. You could create a folder Interfaces within your project. I usually have Concrete, Abstract and Interfaces folders within my projects.
Developers who may be unfamiliar with your solution will have a hard time finding interfaces if they are in class files.

Get c# classes after a program is compiled [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a program that I am making for a friend and I don't want him to see the whole code, but I want him to be able to add classes that have attributes on the classes so he can add his own stuff to it, how would I be able to get classes using a compiled program and add them to the dictionary of methods to be called upon later?
Use MEF.
The Managed Extensibility Framework or MEF is a library for creating
lightweight, extensible applications. It allows application developers
to discover and use extensions with no configuration required. It also
lets extension developers easily encapsulate code and avoid fragile
hard dependencies. MEF not only allows extensions to be reused within
applications, but across applications as well.

Categories