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 2 years ago.
Improve this question
I'm a beginner C# developer and I'm branching out into looking at certain parts of what some more advanced bits of code. However, I cannot wrap my head around how developers and programmers use the "using" commands effectively. I understand how they work, and if they are a public class file they can have their methods accessed, but how do programmers know from picking up an API how to use it?
Sorry if this question seems like a total breeze and as though I've misunderstood the concept entirely (maybe I have, haha) but it seems like something where without extensively going through the API and it's documentation, most people can chew through these things quite easily.
First of all, not sure if you are aware of not, but the using directive does not actually "import" or start "using" anything. using System; merely tells the compiler that whenever you use something like DateTime, it will check System.DateTime and try to look for the type there. In fact, you can write in C# without using the using directive at all (unless you need to resolve a naming conflict), but of course the program will become unnecessarily "wordy".
As for the other part of your question, you don't begin writing a C# program starting with using. You first have to find the proper "tools" (classes) for the problem you are trying to solve by the program, and only then add using so that you can work with them efficiently without typing the namespace over and over. Moreover, most modern IDEs will add the directive automatically, either when you create a new file (adding some common namespaces), or when you use a class in a namespace that you forgot to import with using.
Related
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 would like to scan an economic calendar (and in a second step possibly a news source) like this one for use in MetaTrader/MQL5. I guess I would need another programming language than MQL5 for that, possibly (but not necessarily) C#? (How) can it be done in principle?
Thank you very much in advance!
You can check whether you can access that web page through WebRequest() function available in MT4/5. Alternative way is to write a DLL (or to find one) and access the link above through the REST api (but it doesnt make sense as WebRequest provides it) or somehow else. The easiest way is to check all calendars you may find (myfxbook, mt5.com, fxfactory) and find the easiest page to parse with MT5 methods, then try to collect data and process it. If your skills include some other languages, it might make sense to collect data with REST and then parse it with Jsoup/soup/beautiful-soup (the library that is designed for your language) - that will help with tests (to clear the data faster), and WebRequest() for live.
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 6 years ago.
Improve this question
I'm trying to make a console program in C# that is independent from using System or any other libraries, that includes Console.WriteLine();. I'm making an SDK written in C# (almost like what Unity 3D does). However I don't know how to make a custom text printer. I've found no articles on the web or Stackoverflow questions related to what I want to do. There has to be someway of doing this, or Console.WriteLine(); wouldn't exist.
Here is my code so far, but I don't know how much it will help:
public static class GPrint
{
public static void Print(string str)
{
}
}
I've explored almost all of the obvious stuff like string.something() and str.something(), but there seems to be nothing related to printing a string on the screen.
Is there any way I can make a simple Console.WriteLine() clone without using the provided System namespace?
Thanks in advance!
System.Console, an abstraction over stdin/stdout is so inherent to processes that the .NET team decided to incorporate it into the common object runtime library (mscorlib).
In other words, letting a process receive input and emit output over the standard streams is so ingrained into the runtime and the base class library, that it it not possible, or at least not feasible, to have one without the other.
It's not like you can run a .NET console application omit loading the .NET Framework altogether, just because you're not using System.Console or any other class from the System namespace.
See also Hans' answer in Is mscorlib.dll/mscoree.dll loaded when .NET application runs:
Technically it is possible to not get mscorlib.dll loaded [...] Practically that only works if you provide a substitute
If you're not looking to omit mscorlib altogether, but really just are curious about writing to the console without using System.Console, see MSDN: Console Functions. You'll have to use Platform Invoke. This will come at a price though: your application will then only run on Windows, unless the platform you're running on substitutes the relevant DLLs.
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 9 years ago.
Improve this question
I work in a code base that is quite large and today I found a project that was emitting IL code inside a normal class.
The project containing the IL code being emitted was a implementation of a Service Locator MSDN Desctiption.
What are the advantages of doing this and why would this be done as apposed to using the C# language?
Typically this is done to circumvent the overhead of using reflection, using information only available at runtime.
You would then use reflection, which can be slow depending on what you do, to build a new piece of code that works directly with the data given to it, without using reflection.
Advantages:
Performance
Disadvantages:
Hard to debug
Hard to get right
Hard to read code afterwards
Steep learning curve
So you need to ensure it's really worth the price before embarking on this.
Note that this is a general answer. In the specific case you came across, there is no way to answer why this was done nor which particular advantages (or disadvantages) you would have without actually seeing the code.
There are many uses for this.
One of the more often used scenario is for changing/injecting code on the fly:
.NET CLR Injection: Modify IL Code during Run-time
A good tutorial that help me to understand a good use for it is:
Dynamic... But Fast: The Tale of Three Monkeys, A Wolf and the DynamicMethod and ILGenerator Classes
Good luck
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 3 years ago.
Improve this question
Is there a way to obfuscate c# code (visual studio solution ) so that if soem one even get the project could not understand it ?
note: I'm not talking bout obfuscating assembly/Executable here..
I've not seen anything commercially, but you could probably write your own application to do this. I actually know someone once did this for some ASPX pages that were being deployed.
You'd have to take similar steps:
Rename all local variables to very similar names B___0, B_0 etc.
Rename all internal and private methods/classes and all their references.
Encode all your strings.
Insert random code/calls that don't do anything.
Consider why you want this though... It means:
You can't ever view your own code. You'll have the original somewhere - why not just password protect it?
You're going to screw with any source control you're running.
You're going to have some crazy "process my entire solution" everytime you save/publish it?
In short it's probably not a good idea, which is why you probably can't find a commercial solution.
Close the door and windows tight.
Disconnect your computer from Internet during the developement.
Obfuscate your assemblies when your done.
Save them a a disk.
Burn down your computer.
Keep hitting your head onto a wall until you fergot why you're doing it.
There, you're safe, nobody will ever have the same exact source.
I hope your application has no bug, though.
A more sensible alternative might be to just encrypt your hard drive using something like
BitLocker or
TrueCrypt.
Obfuscate the dll
Use a decompiler like ILSpy and decompile the dll
This way you get obfuscated C# code.
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
Is it possible to convert an AVI file to 3gp in C# ? If so how could I do this? Any ideas will be appreciated, thanks in advance.
It depends what you mean by "convert". Both 3GP and AVI are wrapper formats, so are you merely trying to change the container format, or do you want to re-encode the streams as well?
Either way, you should probably take a look at ffmpeg (Windows info). For simple cases (i.e. you have the file, want a single output file), you should probably consider it invoking it on the command-line (i.e. System.Diagnostics.Process), which is much easier (and doesn't involve any licensing issues). If you want to access libavcodec/libavormat programatically, I highly recommend skipping any .NET wrapper libs (they all are in different states of sucking; Tao being the best but that's not saying much) and instead writing a C++/CLI wrapper. I started doing this, and once I got my head around data marshalling, etc., and figured out how to build it (Part 1, Part 2), it wasn't too hard.
There is no really easy way to do it; my advice is to use ffmpeg, either through the use of a C# wrapper of by calling it externally. There seem to be several C# wrappers for ffmpeg (like this one) but they all seem to be in various stages of development and not really usable. Your only option is likely going to be by calling it externally.