Microsoft Visual C Sharp

From Wikipedia, the free encyclopedia
Jump to: navigation, search
The correct title of this article is Microsoft Visual C#. The substitution or omission of the # is because of technical restrictions.
Visual C#
Logo C Sharp.png
Developer(s) Microsoft
Stable release 2012 / August 15, 2012; 22 months ago (2012-08-15)
Development status Active
Operating system Windows XP and later
Platform .NET Framework
Available in English, French, Japanese, Korean, German, and likely others
Type Integrated development environment
License Proprietary software; both shareware and freeware versions available
Website msdn.microsoft.com/en-us/vstudio/hh388566

Microsoft Visual C# is Microsoft's implementation of the C# specification, included in the Microsoft Visual Studio suite of products. It is based on the ECMA/ISO specification of the C# language, which Microsoft also created. While multiple implementations of the specification exist, Visual C# is by far the one most commonly used.[1] In most contexts, an unqualified reference to "C#" is taken to mean "Visual C#."[citation needed]

The term Visual denotes a brand-name relationship with other Microsoft programming languages such as Visual Basic, Visual FoxPro, Visual J# and Visual C++. All of these products are packaged with a graphical IDE and support rapid application development of Windows-based applications.

Visual C# is currently used in development of Windows and Xbox Live games via Microsoft XNA, which allows game developers to create and share their games with other gamers. Visual C# is also heavily used by ASP.NET web sites and standalone applications based on the .NET Framework. Note: As of October 2012 Microsoft has ended support and future releases of XNA.

IDE[edit]

Visual C sharp start page

When you start Visual C#, Start Page is displayed. Start Page has two columns; the left column holds Start and Recent sections. These sections contain options for developers to create a new application or work with an existing one, respectively.[2]

Visual C# places Get Started and Latest News tabs in the left column so developers can find useful information about application development, resources, and a tutorial. It is necessary for the user to have an internet connection to access the latest news.[2]

Menu bar provides functions to developers for coding, maintaining and executing their programs. Menu bar contains:

  • DEBUG: used for compiling, debugging and running apps.
  • TEAM: contains functions to connect to Team Foundation Server.
  • FORMAT: contains commands to arrange and modify Form’s controls.
  • TOOLS: contains commands to customize the IDE.[2]

Syntax[edit]

Visual C# is an object oriented programming language (OOP); its syntax is very similar to C++ or Java. The important parts of the syntax are variables. Visual C# uses operators to change variables values, to create classes, methods and pass data to these methods.[3]

Developing desktop software[edit]

Visual C# controls

Basics[edit]

Visual C# uses System.Windows.Forms.Control class to create most controls for developers, such as label, text box, button, and checkbox. These controls are inherited as shown in the figure.[1]

Properties describe shape, size and other characteristics of control. Controls inherit or override properties, which defined in the System.Windows.Forms.Control class to create their own properties. The following table lists some common properties of Visual C# controls.[1]

Name Description
BackColor Get or set the background color.
Enabled Get or set Enabled characteristic of control. Set to "True" means that control can receive data from a user and "False" means users can't interact with control.
ForeColor Get or set the ForeColor.
Height Get or set the height of control.
Name Get or set the name of control. Developer uses this name to refer to the control when they are coding.
Right Get the right edge of control relative to the top of its container.
Text Get or set the text presented in control.
Top Get or set the top edge of control relative to the top of its container.
Visible Get or set the visible of control.
Width Get or set the width of control.

Visual C# provides Windows.Forms.Controls class to create Events. These Events will be activated when there is an action. For example, when a user click a button will raise a Click_Event of this button. Developers are expected to write a method to handle these actions. Their code blocks are called Event Handlers.[1]

There are three options to work with Event Handler. The simplest way is to double-click control when you want to add Event Handler. Visual C# will display the default Event Handler of this control. If developers need other Event, they have two ways to find it. They can use the Properties window located on the right side of Visual C# IDE. It lists all Events of the control and developers can pick the desired Event. The quickest way is if the developer types a definition of this Event Handler directly into the code editor, but this requires a lot of experience.[1]

Name Description
Click Raises when user clicks a control
DoubleClick Raises when user double-click a control
KeyDown Raises when user press a key while the control has focus
GotFocus Raises when user select a control
MouseDown Raises when user moves the mouse over a control and press a mouse button
MouseMove Raises when user moves the mouse over a control

Example[edit]

When creating a Windows application, developers first design user interface by using controls which is available in the Toolbox window. Programmers add an instance of a control into a form by double-clicking on this control template. Microsoft Visual C# provides most controls need to build a user interface, developers can also buy a custom control from third party software companies. After the user interface is created, the next step is adding Event Handler to these controls. Click on a button, Visual C# will generate a method as follows:[1]

private void buttonName_Click(object sender, EventArgs e)
{
    //Place your code here
}

The code block defines a method called "buttonName_Click", as you can see; names of the button and Event are combined to form the name of method. This method will be executed when user click on the button. In this case, there are two parameters. The object sender parameter indicates a control which user clicks on, and the eventArgs e provides information of what exactly happened with control.[1]

Deployment[edit]

Visual C# provides ClickOnce for developers to help them to distribute their applications more easily. When users want to install an application, all they need to do is click on a link in the installation Webpage. After the installation is finished, users can be offline, there no need to access to the Webpage if they do not want to update their software. The application is available on the Start menu in client system; it can be uninstalled with Add/Remove program dialog. ClickOnce uses manifest files for describing an application, permission required, configuration information and update policies.[1]

Developing Windows Store apps[edit]

Microsoft designed Windows 8 with the intent to provide a platform to the next generation of mobile devices. Users install Windows 8 operating system on their laptop can feel like they are using a tablet or smartphone. Users can input data into their system by using a touch sensitive screen and they can know their system location or orientation if the device hardware supports appropriate sensors. Developers can upload applications to Windows Store to share with other people. For this reason, those applications are known as Windows Store apps.[3]

Multitasking[edit]

Developers use multitasking approach while developing an application when they want to achieve:

Responsiveness: If programmers divided an application into small threads and assigned a short time period to each thread, users can feel that the application can run multi tasks at the same time. However, this is not true multitasking because these threads share the computing time of the processor. The advantage will be lost if there was a thread which dominated time consuming. In the past, it was not easy to implement true multitasking in an application. Now, Windows 8 with Windows Runtime provides many API functions to address this issue.[3]

Scalability: Scalability can be increased if an application handles computing resource better. Developers identify which parts of an application can be processed in parallel manner and make an executing schedule for them. The MPI (Message Passing Interface) protocol provides mechanism so that parallel tasks can communicate to each other by sending a message.[3]

In a multiprocessors system or a system with multicore processor, an application can execute a number of concurrent tasks, which will not exceed the number of processors (or cores). If an application always uses all of these processors, it will be finished very quickly. Programmers have to answer the following questions then they want to put their applications in multitasking mode:[3]

  • How to identify which parts are parallel
  • How to ensure that number of concurrent task at a time will not exceed the number of processors in the system
  • Suppose that there is a task waiting for an I/O operation, how to recognize this task and indicate the application to switch to another task
  • Which sign show that a task is completed

Developers use Task class and System.Threading.Tasks namespace to address this issue. A concurrent task is an instance of Task class, it is used to execute inside code block. For example, to run a job named doThisWork, a Task object is defined as follows:[3]

Task task = new Task(doThisWork);
 
private void doThisWork (){
    // The task runs this code when it is started ...
}

and execute this Task by Start method:

Task task = new Task(...);
task.Start();

Asynchronous operations[edit]

User interface also is a concurrent task, and users want to interact with the application even when this application is doing another complicated task. The answer to this problem is executing all the tasks in asynchronous manner. Visual C# provides a platform for developers to overcome the difficulty of defining asynchronous methods.[3]

An asynchronous method is the method in executing mode will not block current thread. It returns control permission to calling environment as soon as possible. Programmers use await and async keywords to declare a synchronous method, for example:[3]

private async void slowMethod()
{
    await doFirstLongRunningOperation();
    await doSecondLongRunningOperation();
    await doThirdLongRunningOperation();
    messages.Text = "Processing Complete";
}

Windows Store apps[edit]

Windows Store apps usually consume the whole screen of a device so they do not have borders, menu or popup dialogs. In other word, they are chromeless. Developers believe that these components distract users, so Windows Store apps are designed without these traditional elements to help users focus on their task.[3]

When developers create a new Windows Store app, Visual C# helps them to package and upload the application to Windows Store so that other people can access this application. Applications must pass all the security test of Microsoft so that it can reside in Windows Store. Developers can make their applications free or they can charge for their development time and effort.[3]

References[edit]

  1. ^ a b c d e f g h Watson, K et al., (2010). Beginning Visual C# 2010. Indianapolis, Indiana: Wiley.
  2. ^ a b c Deitel, P et al., (2014). Visual C#2012 how to program. Boston : Prentice Hall.
  3. ^ a b c d e f g h i j Sharp, J. (2012). Microsoft Visual C# 2012 step by step. Sebastopol, California : O'Reilly Media, Inc.

External links[edit]