Top Banner
VB and C# Programming Basics
38

VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Jan 03, 2016

Download

Documents

Amberly Parsons
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

VB and C# Programming Basics

Page 2: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Overview

• Basic operations

• String processing

• Date processing

• Control structures

• Functions and subroutines

Page 3: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Additional Documentation

• For extensive documentation in Microsoft .NET Development using VB or C#:– http://msdn.microsoft.com/en-us/library/dd642420.aspx

Page 4: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
Page 5: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
Page 6: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
Page 7: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

The System Namespace

• Contains fundamental classes, including String and DateTime

• System Namespace Documentation– http://msdn.microsoft.com/en-us/library/

system.aspx

Page 8: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

String Processing

• Concatenation

• String length

• Substrings

• Changing case

• Replacing text

• Hyperlink to String class documentation

Page 9: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

String concatenation

Page 10: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Note: C# is case sensitive. Length property begins with upper-case “L”

Returning string lengths

Page 11: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Substring method of String class.

1st argument = start position

2nd (optional) argument = length of substring

Page 12: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Indexof method of String class

Returns the 0-based index position of the substring in the searched string.

Syntax:

searchedString.Indexof(stringToFind)

searchedString.Indexof (stringToFind, startPos)

Page 13: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Changing case

Page 14: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Replacing text in a string

Page 15: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

The DateTime Class

• Provides many useful properties and methods related to dates and times

• Hyperlink to DateTime documentation

Page 16: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Date Manipulation

Lots of methods and properties for the DateTime class!

Page 17: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Additional Notes

• In C#, use DateTime.Parse static method to convert a string to date. Not necessary in VB.– Try changing from DateTime.Now to a string

representing a date and time

• To make the view source more readable, you can insert line breaks in your output string:– “\n” for C#

– ControlChars.CrLf for VB

Page 18: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Control Structures

• Selection– if – else– select case ----- switch

• Looping– for loops– while and do while loops

Page 19: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Syntax for if statements in C# is identical to what you know from Java

Page 20: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

VB Select-Case like before

Page 21: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Note: C# switch statement allows case to include strings…different from Java, which requires integral values

Page 22: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

for loop syntax similar to what you know of Java

Page 23: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Note: unlike Java, C# includes a foreach keyword in the core language.

Page 24: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

while in C# is similar to what you know already in Java

Page 25: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Functions and Subroutines

• Signatures – return type, name, parameter list

• Calling functions and subroutines

• Making use of return values

Page 26: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Note: with VB .NET, explicit type declarations not necessary

Note the use of ToString method…converts numeric values to strings for text output.

Page 27: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Note that the int data type (and other primitive data types) provides the possibility of converting data to string via ToString(). In this sense it operates like a Java wrapper class.

Page 28: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Array Processing• Topics:

– Array declaration, instantiation, initialization– Single-dimensional arrays– Multi-dimensional arrays– Jagged arrays

Page 29: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Single Dimension Arrays C#Declaration in C# is strict, brackets must follow data type: int[] array1; NOT int array1[];

Looping through arrays can be done using Length property or via for each loop

Page 30: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Single Dimension Arrays VB

Page 31: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Multi Dimension Arrays C#

Multi-dimension array declaration and use in C# is unlike Java. With Java you are always declaring jagged arrays, but C# has a feature for multi-dimension arrays

Page 32: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Multi Dimension Arrays VB

Length vs. GetLength():

Length returns full array sizeGetLength(x) returns nbr elements in row x

Page 33: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Jagged Arrays C#

Jagged arrays are familiar to Java programmers

Page 34: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Jagged Arrays VB

Page 35: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Web Server Controls for Assignment #1

• TextBox – Two Useful Properties:

• Text – contains the string for user input

• Columns – specifies visible number of characters

• Button– Event processing via ONCLICK attribute in

ASP:Button tag

• Label– Static text display

Page 36: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Note initialization of server control properties in the Page_Load procedure

Association of click event with event-handling routine

Page 37: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

Resulting HTML code

Resulting browser render

Page 38: VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.

The web.config file

• Useful for deployment and configuration• Primarily for web administration• Can also be used for creating global application variables• XML file• If used, should be placed in application’s root folder• For debugging purposes, you should do the following……• In your web.config file, change the tag that says:

– <customErrors mode="RemoteOnly" /> • To

– <customErrors mode="Off"/>• This will enable compile errors in your code to be identified when

attempting to view the page in a browser