-3

I am very familiar with C and C++, but I am new to C#. Is there any way of including C++ commands in a C# program? For example:

cout << "Hello world" ;

I realize that C# is a visual language, but it seems like such commands as

Console.WriteLine("Hello world");

is awkward if you just want to send something to the screen.

This example is only one example. I am not trying to say that one language is better than the other, but in some cases within a single program to use a command native to C++ than one than one from C#.

halfer
  • 19,824
  • 17
  • 99
  • 186
James N
  • 84
  • 2
  • 11
  • 3
    You can't do that. You need to learn idiomatic C#. – SLaks Oct 14 '16 at 16:41
  • 7
    Maybe you should continue to program in C++? – Some programmer dude Oct 14 '16 at 16:41
  • .. and then compile the c++ code and add it to the c# project :) – ΦXocę 웃 Пepeúpa ツ Oct 14 '16 at 16:45
  • Technically you could use C++/CLI (if you're on Windows with Visual Studio). But you have to already be pretty good with both C++ and .NET to use it properly. And you can't write C# in it. – Cameron Oct 14 '16 at 16:50
  • http://www.ecma-international.org/publications/standards/Ecma-372.htm – bengrine Oct 14 '16 at 16:51
  • You think `Console.WriteLine("Hello world");` is awkward and yet you say you're very familiar with C which has the exact same syntax `printf("Hello world");` ?!?!? – Hatted Rooster Oct 14 '16 at 16:52
  • What exactly do you find awkward? The length of `Console.WriteLine` or the syntax function call syntax `F()`? – Theodoros Chatzigiannakis Oct 14 '16 at 16:53
  • 2
    The really is no such thing as a 'visual language'. – TaW Oct 14 '16 at 17:00
  • @TaW I'd call [this](https://scratch.mit.edu) a 'visual language'. – Bill Tür stands with Ukraine Oct 14 '16 at 21:11
  • Right. I meant of course that the 'Visual' in VS in no way means that C# or VB are in any way more 'visual' than c++.. – TaW Oct 14 '16 at 21:23
  • Hi James. Please don't add voting advice/commentary here - there is no value in it for several reasons. Firstly, downvoters will have long gone by the time you've edited in such messages. Also, most users do not log in or vote, so for them it is just extra words to read that do not aid them. – halfer Oct 16 '16 at 21:41
  • Also, my view is that it is worth noting that one of the guidelines for posting here is that you need to be happy for other people to edit your posts. Whilst you're welcome to rollback or edit things where the substantive meaning of your post has been incorrectly changed, it is also worth considering keeping changes from experienced users whilst you're learning the ropes. We do prefer succinct posts here. – halfer Oct 16 '16 at 21:43

2 Answers2

0

You can't use C++s standard library in C#.

What you can do, however, is use C#s standard library (.NET) in C++.

Another option would be to write critical modules in C++ and link with them from C#.

Ivan Rubinson
  • 3,001
  • 4
  • 19
  • 48
0

These are not commands these are statements from two different programming languages for doing same thing. Since C# statements is Idiomatic it tries to mimic natural language as much as it can.

But if your goal is to simplify console statement you can do the following. 'using static' will make it more cleaner

using static System.Console;
namespace Sample
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Write("Some text");
        }
    }
}
Umamaheswaran
  • 3,690
  • 3
  • 29
  • 56