Partilhar via


Getting Started: Choosing a programming language

[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]

Choosing a programming language

Before we go any further, you should know about the programming languages that you can choose from when you develop Windows Store apps. Although the walkthroughs in this article use C#, you can develop Windows Store apps using several programming languages (see Languages, tools and frameworks).

You can develop Windows Store apps using C++, C#, Microsoft Visual Basic, and JavaScript. JavaScript uses HTML5 markup for UI layout, and the other languages use a markup language called Extensible Application Markup Language (XAML) to describe their UI.

Although we're focusing on C# in this article, the other languages offer unique benefits, which you may want to explore. For example, if your app's performance is a primary concern, especially for intensive graphics, then C++ might be the right choice. The Microsoft .NET version of Visual Basic is great for Visual Basic app developers. JavaScript with HTML5 is great for those coming from a web development background. For more info, see one of the following:

Note  For apps that use 3D graphics, the OpenGL and OpenGL ES standards are not available for Windows Store apps. However, you can use Microsoft DirectX. Like OpenGL ES 2.0, DirectX 11 supports a programmable pipeline and uses a Microsoft High Level Shader Language (HLSL) that is comparable to the OpenGL Shading Language (GLSL). To learn more about DirectX, see the following:

 

As an iOS developer, you're accustomed to Objective-C. The closest Microsoft programming language to Objective-C is C#. For most developers and most apps, we think C# is the easiest and fastest language for Objective-C developers to learn and use, so this article's info and walkthroughs focus on that language. To learn more about C#, see the following:

Following is a class written in Objective-C and C#. The Objective-C version is shown first, followed by the C# version. In C#, you'll see that the header and the implementation are not in separate files.

// Objective-C header: SampleClass.h.

#import <Foundation/Foundation.h>

@interface SampleClass : NSObject {
    BOOL localVariable;
}

@property (nonatomic) BOOL localVariable;

-(int) addThis: (int) firstNumber andThis: (int) secondNumber;

@end

// Objective-C implementation.

#import "SampleClass.h"

@implementation SampleClass

@synthesize localVariable = _localVariable;

- (id)init {
    self = [super init];
    if (self) {
        localVariable = true;
    }
    return self;
}

-(int) addThis: (int) firstNumber andThis: (int) secondNumber {
    return firstNumber + secondNumber;
}

@end

// Objective-C usage.

SampleClass *mySampleClass = [[SampleClass alloc] init];
mySampleClass.localVariable = false;
int result = [mySampleClass addThis:1 andThis:2];
// C# header and implementation.

using System;

namespace MyApp  // Defines this code's scope.
{
    class SampleClass
    {
        private bool localVariable;

        public SampleClass() // Constructor.
        {
            localVariable = true;
        }

        public bool myLocalVariable // Property.
        {
            get
            {
                return localVariable;
            }
            set
            {
                localVariable = value; 
            }
        }

        public int AddTwoNumbers(int numberOne, int numberTwo)
        {
            return numberOne + numberTwo;
        }        
    }
}
// C# usage.

SampleClass mySampleClass = new SampleClass();
mySampleClass.myLocalVariable = false;
int result = mySampleClass.AddTwoNumbers(1, 2);

Next step

Getting started: Getting around in Visual Studio