

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A part of the lecture notes for cs 112 introduction to programming at yale university. It covers the topic of characters, including the use of double-subscripted arrays for rectangular and jagged arrays, and the encapsulation of an array of characters in the string class. The document also introduces inheritance, a programming concept that allows a new class to inherit characteristics from an existing one. The example provided demonstrates the use of static char methods from the char structure to test various properties of a character. A code example of a windows forms application that takes a character input and displays its corresponding properties.
Typology: Slides
1 / 3
This page cannot be seen from the preview
Don't miss anything!


1 // StaticCharMethods.cs 2 // Demonstrates static character testing methods 3 // from Char structure 4 5 using System; 6 using System.Drawing; 7 using System.Collections; 8 using System.ComponentModel; 9 using System.Windows.Forms; 10 using System.Data; 11 12 // Form displays information about specific characters. 13 public class StaticCharMethods : System.Windows.Forms.Form 14 { 15 private System.Windows.Forms.Label enterLabel; 16 private System.Windows.Forms.TextBox inputTextBox; 17 private System.Windows.Forms.Button analyzeButton; 18 private System.Windows.Forms.TextBox outputTextBox; 19 20 private System.ComponentModel.Container components = null; 21 22 // The main entry point for the application. 23 [STAThread] 24 static void Main() 25 { 26 Application.Run( new StaticCharMethods() ); 27 } 28 29 // Visual Studio .NET generated code 30
31 // handle analyzeButton_Click 32 private void analyzeButton_Click( 33 object sender, System.EventArgs e ) 34 { 35 char character = Convert.ToChar( inputTextBox.Text ); 36 BuildOutput( character ); 37 } 38 39 // display character information in outputTextBox 40 private void BuildOutput( char inputCharacter ) 41 { 42 string output; 43 44 output = "is digit: " + 45 Char.IsDigit( inputCharacter ) + "\r\n"; 46 47 output += "is letter: " + 48 Char.IsLetter( inputCharacter ) + "\r\n"; 49 50 output += "is letter or digit: " + 51 Char.IsLetterOrDigit( inputCharacter ) + "\r\n"; 52 53 output += "is lower case: " + 54 Char.IsLower( inputCharacter ) + "\r\n"; 55 56 output += "is upper case: " + 57 Char.IsUpper( inputCharacter ) + "\r\n"; 58 59 output += "to upper case: " + 60 Char.ToUpper( inputCharacter ) + "\r\n"; 61 62 output += "to lower case: " + 63 Char.ToLower( inputCharacter ) + "\r\n"; 64
65 output += "is punctuation: " + 66 Char.IsPunctuation( inputCharacter ) + "\r\n"; 67 68 output += "is symbol: " + Char.IsSymbol( inputCharacter ); 69 70 outputTextBox.Text = output; 71 72 } // end method BuildOutput 73 74 } // end class StaticCharMethods