Docsity

C# Programming for VB Developers: Key Terms, Project Structure, and Differences, Slides of Computer Programming

Partial preview of the text

Download C# Programming for VB Developers: Key Terms, Project Structure, and Differences and more Slides Computer Programming in PDF only on Docsity!

Introduction to the C#

Programming Language

for the VB Programmer

Lecture Overview

 Some key terms  Introduce the C# programming language for the VB developer  Mention some important features of the Visual Studio .NET environment  Pass along some editing tips and tricks

Key Terms (2)

Object – A class instance. Once an object has been created from its class, it’s possible to call methods and read and write properties  Objects are created when a class’ constructor is called

Project Structure

 Everything is the same as VB  Solution file, project file, program files

 Modules have a file suffix of .cs instead of .vb

Statements

 In C#, all statements end with a semicolon ;  Statements can span multiple lines  There is no need for a continuation character as in VB  Example C# System.Console.WriteLine( “This is a line of text”);  Example VB System.Console.WriteLine( _ “This is a line of text”);

Comments

 XMLSummary comments begin with ///  Single line comments are marked with //  Multi-line comments start with /* and end with */

// A comment.

/ This is Also a comment /

Data Types

C# VB int Integer bool Boolean string String double Double float Single date DateTime

Variable Declaration

(Examples)

 VB

Dim Count As Integer Dim MyName As String = “Ekedahl”

 C#

int count; string MyName = “Ekedahl”;

Strings

 Use the System.String data type as in VB;  The C# string type maps to System.String  the string concatenation operator is + instead of &  The members are the same between C# and VB

Type Conversion

(Introduction)

 In IS 350, you used val to convert strings to numbers  In C#, val is used to declare implicitly typed variables  We will use a much different strategy here  Each primary data type supports a method named TryParse  The method accepts 2 arguments  The string to parse  The output result

Using System.Convert

 Members of System.Convert class also convert one type to another  System.Convert.ToIntSystem.Convert.ToDoubleSystem.Convert.ToDateTime  …

Constants

 Constants are just variables whose value does not ever change  Declare with the const statement  Constants can only be initialized when they are declared

Scope

 Access modifiers control the scope of a procedure or variable  The keywords are the same between VB and C#  private – scope is the class containing the procedure or variable  public – scope is global

C# Blocks

 In VB, blocks are marked with keywords  Sub – End SubIf – End IfDo LoopWhile End While  In C#, blocks are all marked with {} as in Java or C++