https://imamp.colum.edu/mediawiki/api.php?action=feedcontributions&user=Cameron.Cintron&feedformat=atom IAM MediaWiki - User contributions [en] 2024-03-28T12:31:53Z User contributions MediaWiki 1.28.0 https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class4&diff=21748 OOP Class4 2013-09-26T18:23:36Z <p>Cameron.Cintron: /* Video */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> =Classes and Objects=<br /> ==Objects==<br /> <br /> Object-oriented programs are made up of objects. <br /> :&quot;An object packages both data and the procedures that operate on that data. The procedures are typically called methods or operations. An object performs an operation when it receives a request(or message) from a client. &quot; - Design Patterns Addison Wesley<br /> Reasons for organizing code into Classes and Objects<br /> <br /> * avoid spaghetti<br /> * organize code into logical sections<br /> * simplify program designs<br /> * reuse<br /> <br /> Classes are sections of code that describe real world objects. Classes define what '''properties''' and '''methods''' an object contains. <br /> Properties<br /> :define data members of classes. Nouns<br /> <br /> Methods <br /> :define what classes can do. Verbs<br /> <br /> ===Abstraction===<br /> <br /> Humans are always abstracting and naming objects. It is how we identify things. Objects are identified by two things: properties(what the have) and methods (what they do).<br /> <br /> Classes are used to define objects. <br /> <br /> The hardest part about object oriented programming is choosing how to build and implement these abstractions. There are many factors that affect these decisions. It can often be very difficult to find a balance between all of the factors.<br /> <br /> * granularity<br /> :the size and acuracy of you abstraction<br /> * re usability<br /> :simpler objects are more reusable<br /> * flexibility<br /> :specialized objects are often less flexible<br /> * performance<br /> * portability<br /> <br /> ==Encapsulation==<br /> <br /> Allows us to use objects with out completely understanding how everything inside the object works. Encapsulation also allows the internal state of objects to be changed easily without affecting other objects or interfaces. For example you don't need to know how the phone system works in order to use a telephone. All you really need to know to use the phone system is how to dial a phone<br /> Classes<br /> <br /> Classes are used to create objects.<br /> a simple example of class syntax in c#<br /> <br /> &lt;csharp&gt;public class Dog{ }&lt;/csharp&gt;<br /> <br /> class syntax full<br /> <br /> [attributes] [access modifiers} class identifier [:base class]<br /> {class body}<br /> <br /> Objects are instances of classes. For instance a Dog class may describe what dogs are like. <br /> <br /> All dogs have specific properties like height, weight, color. Dog also have methods like bark. My dog rover is a specific instance of the dog class.<br /> <br /> <br /> &lt;csharp&gt;// Instantiate Dog objects<br /> // Declare an instance of the Dog class<br /> Dog firstDog;<br /> <br /> // Allocate memory for the dog object<br /> firstDog = new Dog();<br /> <br /> // Declare and Allocate in one like<br /> Dog secondDog = new Dog();&lt;/csharp&gt;<br /> <br /> The '''new''' keyword call the classes '''constructor''' which allocated memory on the stack for the object. <br /> <br /> access modifier restrictions <br /> <br /> {|-<br /> |public || No restrictions available to all members of the class.<br /> |-<br /> |private || Members marked private are only available to methods of that class.<br /> |-<br /> |protected || Members marked protected are available to methods of thay class and of classes dreived from that class.<br /> |-<br /> |internal ||Members marked as internal are available to any class within that classes assembly.<br /> |-<br /> |protected internal ||Same as protected and internal<br /> |}<br /> <br /> ==Chair Class==<br /> ===Fields===<br /> * int Height<br /> * int NumLegs<br /> * bool HasBack<br /> * bool HeightAdjustable<br /> <br /> ===Methods===<br /> <br /> * RaiseHeight<br /> * LowerHeight<br /> <br /> ===Chair Class UML===<br /> [[Image:ChairSimpleUML.png]]<br /> <br /> In class do phone class.<br /> <br /> ==Dog Class==<br /> ===Fields===<br /> Microsoft has started call ing public variables fields<br /> <br /> * string Name<br /> * int Age<br /> * int Weight<br /> * string BarkSound<br /> <br /> ===Methods===<br /> <br /> * Bark<br /> * Eat<br /> <br /> ===Dog Class UML===<br /> <br /> [[Image:DogSimpleUML.png]]<br /> <br /> ==Constructors==<br /> <br /> A classes constructor is the method that is run when an instance of the class is created. If you do not provide a constructor the complier provides one for you. The constructor is used to initiate all member properties. Unlike intrinsic types variables that are not initialized will be set to 0 or &quot;&quot; or null by the compiler in the default constructor.<br /> <br /> The constructor allows you to set default values for the properties of the class. If you do not provide a constructor then a default constructor will be provided. The default constructor will initialize all of the properites in the class to empty/zero/null values.<br /> <br /> constructor example<br /> <br /> &lt;csharp&gt;public class Dog<br /> {<br /> public Dog()<br /> {<br /> //constructor code<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> Simple Dog class with constructor<br /> <br /> &lt;csharp&gt;//Dog simple class definition<br /> public class Dog<br /> {<br /> public string Name; // the dog's name<br /> public int Age; // the dog's age<br /> public int Weight; // the dog's weight<br /> public string BarkSound; // the sound of the dog's bark<br /> <br /> public Dog()<br /> {<br /> BarkSound = &quot;Woof!!!&quot;;<br /> }<br /> <br /> public void Bark() { <br /> //put bark code here<br /> }<br /> public void Eat() {<br /> //put eat code here <br /> }<br /> }&lt;/csharp&gt;<br /> <br /> Console Example [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class4/dog1/Dog.cs Dog.cs] &lt;br /&gt;<br /> <br /> ==In Class==<br /> <br /> Make and compile a Cat class with a test class.<br /> *Draw UML for the Cat Class<br /> *Write test class<br /> *Compile and test test class<br /> *Make Dog class<br /> *Test Dog class with test class<br /> <br /> ==OverLoading Constructors==<br /> <br /> Overloading a constructor allows object creation to happen in different ways with different parameters. The class can be overloaded to accept different parameters but each constructor method must have a unique parameter signature.<br /> Dog class with overloaded constructor<br /> <br /> &lt;csharp&gt;//Dog overloaded class definition<br /> public class Dog<br /> {<br /> public string Name; // the dog's name<br /> public int Age; // the dog's age<br /> public int Weight; // the dog's weight<br /> public string BarkSound; // the sound of the dog's bark<br /> <br /> public Dog()<br /> {<br /> BarkSound = &quot;Woof!!!&quot;;<br /> }<br /> public Dog(string newName)<br /> {<br /> Name = newName;<br /> BarkSound = &quot;Woof!!!&quot;;<br /> }<br /> public Dog(string newName, string newBarkSound )<br /> {<br /> Name = newName;<br /> BarkSound = newBarkSound;<br /> }<br /> <br /> public void Bark() { <br /> //put bark code here<br /> }<br /> public void Eat() {<br /> //put eat code here <br /> }<br /> public string About() {<br /> string strAbout = &quot;&quot;;<br /> strAbout += this.Name;<br /> strAbout += &quot; &quot; + this.Age;<br /> strAbout += &quot; &quot; + this.Weight;<br /> strAbout += &quot; &quot; + this.BarkSound;<br /> return strAbout;<br /> }<br /> <br /> }<br /> <br /> <br /> }&lt;/csharp&gt; <br /> <br /> Console Example [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class4/dogOverload.cs dogOverload.cs]<br /> <br /> ==HomeWork==<br /> <br /> 2 own classes 1 course class<br /> <br /> Build two of your own classes that describes some real world objects then build a test class to demonstrate how your class works. Your own class should have properties, methods, and constructors.<br /> <br /> The classes should be in the same visual studio project. The use the program class to create new instances of your classes and set properties and call methods. Use Console.Write to show how properties have been changed and the results of calling the methods.<br /> <br /> 3 pts. It can be anything be creative.<br /> 2 pts. Create the course class UML below.<br /> <br /> [[Image:CourseUML-VS.JPG]]<br /> [[Image:CousreUML-Dia.png]]<br /> <br /> ==Links==<br /> * [http://www.csharphelp.com/archives/archive135.html Operator Overloading In C#]<br /> <br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> <br /> namespace Cat<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Hello I'm a cat program&quot;);<br /> <br /> Cat punkin = new Cat();<br /> Cat bella = new Cat();<br /> <br /> punkin.NAME = &quot;punkin&quot;;<br /> punkin.WEIGHT = 5;<br /> <br /> bella.NAME = &quot;bella&quot;;<br /> bella.WEIGHT = 20;<br /> <br /> Console.WriteLine(punkin.About());<br /> <br /> punkin.Meow();<br /> punkin.Eat();<br /> <br /> Console.WriteLine(punkin.About());<br /> <br /> Console.WriteLine(bella.About());<br /> <br /> Console.ReadKey();<br /> }<br /> }<br /> <br /> public class Cat<br /> {<br /> <br /> //Properties<br /> public string NAME;<br /> public int AGE;<br /> public int WEIGHT;<br /> public bool isUGLY;<br /> public bool isStoopid;<br /> <br /> public string MEOWSOUND;<br /> <br /> //Constructor<br /> public Cat()<br /> {<br /> //set seom default values<br /> this.NAME = &quot;some cats name&quot;;<br /> this.AGE = 0;<br /> this.WEIGHT = 47;<br /> this.isUGLY = true;<br /> this.isStoopid = true;<br /> <br /> this.MEOWSOUND = &quot;Meow!!!!&quot;;<br /> }<br /> <br /> //Methods<br /> public void Meow()<br /> {<br /> //write meow sound to the console<br /> Console.WriteLine(this.MEOWSOUND);<br /> }<br /> <br /> public void Eat()<br /> {<br /> this.WEIGHT++;<br /> Console.WriteLine(&quot;MMMMMM yummy&quot;);<br /> }<br /> <br /> public string About()<br /> {<br /> string strAbout = &quot;&quot;;<br /> strAbout += this.NAME;<br /> strAbout += &quot;\n&quot; + this.WEIGHT;<br /> strAbout += &quot;\n&quot; + this.AGE;<br /> if (this.isUGLY)<br /> {<br /> strAbout += &quot;\nI'm an Ugly cat&quot;;<br /> }<br /> else<br /> {<br /> strAbout += &quot;\nI'm an nice looking cat&quot;;<br /> }<br /> <br /> if (this.isStoopid)<br /> {<br /> strAbout += &quot;\nI'm an stoopid cat&quot;;<br /> }<br /> <br /> return strAbout;<br /> }<br /> <br /> }<br /> <br /> }<br /> &lt;/csharp&gt;<br /> <br /> ==Video==<br /> &lt;html&gt;<br /> &lt;script type='text/javascript' src='http://iam.colum.edu/videotutorials/mediaplayer-5.2/swfobject.js'&gt;&lt;/script&gt; <br /> &lt;div id='mediaspace2'&gt;This text will be replaced&lt;/div&gt; <br /> &lt;script type='text/javascript'&gt;<br /> var so = new SWFObject('http://iam.colum.edu/videotutorials/mediaplayer-5.2/player.swf','mpl','800','600','9');so.addParam('allowfullscreen','true')<br /> ;so.addParam('allowscriptaccess','always');<br /> so.addParam('wmode','opaque');<br /> so.addVariable('file','http://iam.colum.edu/screenz/FA13/OOP_MT/OOP_Class4_MT-Tue/OOP_Class4_MT-Tue.mp4');<br /> so.addVariable('autostart','false');<br /> so.write('mediaspace2');<br /> <br /> &lt;/script&gt;<br /> <br /> &lt;/html&gt;</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class4&diff=21747 OOP Class4 2013-09-26T18:23:10Z <p>Cameron.Cintron: /* Video */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> =Classes and Objects=<br /> ==Objects==<br /> <br /> Object-oriented programs are made up of objects. <br /> :&quot;An object packages both data and the procedures that operate on that data. The procedures are typically called methods or operations. An object performs an operation when it receives a request(or message) from a client. &quot; - Design Patterns Addison Wesley<br /> Reasons for organizing code into Classes and Objects<br /> <br /> * avoid spaghetti<br /> * organize code into logical sections<br /> * simplify program designs<br /> * reuse<br /> <br /> Classes are sections of code that describe real world objects. Classes define what '''properties''' and '''methods''' an object contains. <br /> Properties<br /> :define data members of classes. Nouns<br /> <br /> Methods <br /> :define what classes can do. Verbs<br /> <br /> ===Abstraction===<br /> <br /> Humans are always abstracting and naming objects. It is how we identify things. Objects are identified by two things: properties(what the have) and methods (what they do).<br /> <br /> Classes are used to define objects. <br /> <br /> The hardest part about object oriented programming is choosing how to build and implement these abstractions. There are many factors that affect these decisions. It can often be very difficult to find a balance between all of the factors.<br /> <br /> * granularity<br /> :the size and acuracy of you abstraction<br /> * re usability<br /> :simpler objects are more reusable<br /> * flexibility<br /> :specialized objects are often less flexible<br /> * performance<br /> * portability<br /> <br /> ==Encapsulation==<br /> <br /> Allows us to use objects with out completely understanding how everything inside the object works. Encapsulation also allows the internal state of objects to be changed easily without affecting other objects or interfaces. For example you don't need to know how the phone system works in order to use a telephone. All you really need to know to use the phone system is how to dial a phone<br /> Classes<br /> <br /> Classes are used to create objects.<br /> a simple example of class syntax in c#<br /> <br /> &lt;csharp&gt;public class Dog{ }&lt;/csharp&gt;<br /> <br /> class syntax full<br /> <br /> [attributes] [access modifiers} class identifier [:base class]<br /> {class body}<br /> <br /> Objects are instances of classes. For instance a Dog class may describe what dogs are like. <br /> <br /> All dogs have specific properties like height, weight, color. Dog also have methods like bark. My dog rover is a specific instance of the dog class.<br /> <br /> <br /> &lt;csharp&gt;// Instantiate Dog objects<br /> // Declare an instance of the Dog class<br /> Dog firstDog;<br /> <br /> // Allocate memory for the dog object<br /> firstDog = new Dog();<br /> <br /> // Declare and Allocate in one like<br /> Dog secondDog = new Dog();&lt;/csharp&gt;<br /> <br /> The '''new''' keyword call the classes '''constructor''' which allocated memory on the stack for the object. <br /> <br /> access modifier restrictions <br /> <br /> {|-<br /> |public || No restrictions available to all members of the class.<br /> |-<br /> |private || Members marked private are only available to methods of that class.<br /> |-<br /> |protected || Members marked protected are available to methods of thay class and of classes dreived from that class.<br /> |-<br /> |internal ||Members marked as internal are available to any class within that classes assembly.<br /> |-<br /> |protected internal ||Same as protected and internal<br /> |}<br /> <br /> ==Chair Class==<br /> ===Fields===<br /> * int Height<br /> * int NumLegs<br /> * bool HasBack<br /> * bool HeightAdjustable<br /> <br /> ===Methods===<br /> <br /> * RaiseHeight<br /> * LowerHeight<br /> <br /> ===Chair Class UML===<br /> [[Image:ChairSimpleUML.png]]<br /> <br /> In class do phone class.<br /> <br /> ==Dog Class==<br /> ===Fields===<br /> Microsoft has started call ing public variables fields<br /> <br /> * string Name<br /> * int Age<br /> * int Weight<br /> * string BarkSound<br /> <br /> ===Methods===<br /> <br /> * Bark<br /> * Eat<br /> <br /> ===Dog Class UML===<br /> <br /> [[Image:DogSimpleUML.png]]<br /> <br /> ==Constructors==<br /> <br /> A classes constructor is the method that is run when an instance of the class is created. If you do not provide a constructor the complier provides one for you. The constructor is used to initiate all member properties. Unlike intrinsic types variables that are not initialized will be set to 0 or &quot;&quot; or null by the compiler in the default constructor.<br /> <br /> The constructor allows you to set default values for the properties of the class. If you do not provide a constructor then a default constructor will be provided. The default constructor will initialize all of the properites in the class to empty/zero/null values.<br /> <br /> constructor example<br /> <br /> &lt;csharp&gt;public class Dog<br /> {<br /> public Dog()<br /> {<br /> //constructor code<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> Simple Dog class with constructor<br /> <br /> &lt;csharp&gt;//Dog simple class definition<br /> public class Dog<br /> {<br /> public string Name; // the dog's name<br /> public int Age; // the dog's age<br /> public int Weight; // the dog's weight<br /> public string BarkSound; // the sound of the dog's bark<br /> <br /> public Dog()<br /> {<br /> BarkSound = &quot;Woof!!!&quot;;<br /> }<br /> <br /> public void Bark() { <br /> //put bark code here<br /> }<br /> public void Eat() {<br /> //put eat code here <br /> }<br /> }&lt;/csharp&gt;<br /> <br /> Console Example [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class4/dog1/Dog.cs Dog.cs] &lt;br /&gt;<br /> <br /> ==In Class==<br /> <br /> Make and compile a Cat class with a test class.<br /> *Draw UML for the Cat Class<br /> *Write test class<br /> *Compile and test test class<br /> *Make Dog class<br /> *Test Dog class with test class<br /> <br /> ==OverLoading Constructors==<br /> <br /> Overloading a constructor allows object creation to happen in different ways with different parameters. The class can be overloaded to accept different parameters but each constructor method must have a unique parameter signature.<br /> Dog class with overloaded constructor<br /> <br /> &lt;csharp&gt;//Dog overloaded class definition<br /> public class Dog<br /> {<br /> public string Name; // the dog's name<br /> public int Age; // the dog's age<br /> public int Weight; // the dog's weight<br /> public string BarkSound; // the sound of the dog's bark<br /> <br /> public Dog()<br /> {<br /> BarkSound = &quot;Woof!!!&quot;;<br /> }<br /> public Dog(string newName)<br /> {<br /> Name = newName;<br /> BarkSound = &quot;Woof!!!&quot;;<br /> }<br /> public Dog(string newName, string newBarkSound )<br /> {<br /> Name = newName;<br /> BarkSound = newBarkSound;<br /> }<br /> <br /> public void Bark() { <br /> //put bark code here<br /> }<br /> public void Eat() {<br /> //put eat code here <br /> }<br /> public string About() {<br /> string strAbout = &quot;&quot;;<br /> strAbout += this.Name;<br /> strAbout += &quot; &quot; + this.Age;<br /> strAbout += &quot; &quot; + this.Weight;<br /> strAbout += &quot; &quot; + this.BarkSound;<br /> return strAbout;<br /> }<br /> <br /> }<br /> <br /> <br /> }&lt;/csharp&gt; <br /> <br /> Console Example [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class4/dogOverload.cs dogOverload.cs]<br /> <br /> ==HomeWork==<br /> <br /> 2 own classes 1 course class<br /> <br /> Build two of your own classes that describes some real world objects then build a test class to demonstrate how your class works. Your own class should have properties, methods, and constructors.<br /> <br /> The classes should be in the same visual studio project. The use the program class to create new instances of your classes and set properties and call methods. Use Console.Write to show how properties have been changed and the results of calling the methods.<br /> <br /> 3 pts. It can be anything be creative.<br /> 2 pts. Create the course class UML below.<br /> <br /> [[Image:CourseUML-VS.JPG]]<br /> [[Image:CousreUML-Dia.png]]<br /> <br /> ==Links==<br /> * [http://www.csharphelp.com/archives/archive135.html Operator Overloading In C#]<br /> <br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> <br /> namespace Cat<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Hello I'm a cat program&quot;);<br /> <br /> Cat punkin = new Cat();<br /> Cat bella = new Cat();<br /> <br /> punkin.NAME = &quot;punkin&quot;;<br /> punkin.WEIGHT = 5;<br /> <br /> bella.NAME = &quot;bella&quot;;<br /> bella.WEIGHT = 20;<br /> <br /> Console.WriteLine(punkin.About());<br /> <br /> punkin.Meow();<br /> punkin.Eat();<br /> <br /> Console.WriteLine(punkin.About());<br /> <br /> Console.WriteLine(bella.About());<br /> <br /> Console.ReadKey();<br /> }<br /> }<br /> <br /> public class Cat<br /> {<br /> <br /> //Properties<br /> public string NAME;<br /> public int AGE;<br /> public int WEIGHT;<br /> public bool isUGLY;<br /> public bool isStoopid;<br /> <br /> public string MEOWSOUND;<br /> <br /> //Constructor<br /> public Cat()<br /> {<br /> //set seom default values<br /> this.NAME = &quot;some cats name&quot;;<br /> this.AGE = 0;<br /> this.WEIGHT = 47;<br /> this.isUGLY = true;<br /> this.isStoopid = true;<br /> <br /> this.MEOWSOUND = &quot;Meow!!!!&quot;;<br /> }<br /> <br /> //Methods<br /> public void Meow()<br /> {<br /> //write meow sound to the console<br /> Console.WriteLine(this.MEOWSOUND);<br /> }<br /> <br /> public void Eat()<br /> {<br /> this.WEIGHT++;<br /> Console.WriteLine(&quot;MMMMMM yummy&quot;);<br /> }<br /> <br /> public string About()<br /> {<br /> string strAbout = &quot;&quot;;<br /> strAbout += this.NAME;<br /> strAbout += &quot;\n&quot; + this.WEIGHT;<br /> strAbout += &quot;\n&quot; + this.AGE;<br /> if (this.isUGLY)<br /> {<br /> strAbout += &quot;\nI'm an Ugly cat&quot;;<br /> }<br /> else<br /> {<br /> strAbout += &quot;\nI'm an nice looking cat&quot;;<br /> }<br /> <br /> if (this.isStoopid)<br /> {<br /> strAbout += &quot;\nI'm an stoopid cat&quot;;<br /> }<br /> <br /> return strAbout;<br /> }<br /> <br /> }<br /> <br /> }<br /> &lt;/csharp&gt;<br /> <br /> ==Video==<br /> &lt;html&gt;<br /> &lt;script type='text/javascript' src='http://iam.colum.edu/videotutorials/mediaplayer-5.2/swfobject.js'&gt;&lt;/script&gt; <br /> &lt;div id='mediaspace2'&gt;This text will be replaced&lt;/div&gt; <br /> &lt;script type='text/javascript'&gt;<br /> var so = new SWFObject('http://iam.colum.edu/videotutorials/mediaplayer-5.2/player.swf','mpl','800','600','9');so.addParam('allowfullscreen','true')<br /> ;so.addParam('allowscriptaccess','always');<br /> so.addParam('wmode','opaque');<br /> so.addVariable('file','http://iam.colum.edu/screenz/FA13/OOP_MT/OOP_Class4_MT_Tue/OOP_Class4_MT-Tue.mp4');<br /> so.addVariable('autostart','false');<br /> so.write('mediaspace2');<br /> <br /> &lt;/script&gt;<br /> <br /> &lt;/html&gt;</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class4&diff=21746 OOP Class4 2013-09-26T18:18:07Z <p>Cameron.Cintron: /* Video */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> =Classes and Objects=<br /> ==Objects==<br /> <br /> Object-oriented programs are made up of objects. <br /> :&quot;An object packages both data and the procedures that operate on that data. The procedures are typically called methods or operations. An object performs an operation when it receives a request(or message) from a client. &quot; - Design Patterns Addison Wesley<br /> Reasons for organizing code into Classes and Objects<br /> <br /> * avoid spaghetti<br /> * organize code into logical sections<br /> * simplify program designs<br /> * reuse<br /> <br /> Classes are sections of code that describe real world objects. Classes define what '''properties''' and '''methods''' an object contains. <br /> Properties<br /> :define data members of classes. Nouns<br /> <br /> Methods <br /> :define what classes can do. Verbs<br /> <br /> ===Abstraction===<br /> <br /> Humans are always abstracting and naming objects. It is how we identify things. Objects are identified by two things: properties(what the have) and methods (what they do).<br /> <br /> Classes are used to define objects. <br /> <br /> The hardest part about object oriented programming is choosing how to build and implement these abstractions. There are many factors that affect these decisions. It can often be very difficult to find a balance between all of the factors.<br /> <br /> * granularity<br /> :the size and acuracy of you abstraction<br /> * re usability<br /> :simpler objects are more reusable<br /> * flexibility<br /> :specialized objects are often less flexible<br /> * performance<br /> * portability<br /> <br /> ==Encapsulation==<br /> <br /> Allows us to use objects with out completely understanding how everything inside the object works. Encapsulation also allows the internal state of objects to be changed easily without affecting other objects or interfaces. For example you don't need to know how the phone system works in order to use a telephone. All you really need to know to use the phone system is how to dial a phone<br /> Classes<br /> <br /> Classes are used to create objects.<br /> a simple example of class syntax in c#<br /> <br /> &lt;csharp&gt;public class Dog{ }&lt;/csharp&gt;<br /> <br /> class syntax full<br /> <br /> [attributes] [access modifiers} class identifier [:base class]<br /> {class body}<br /> <br /> Objects are instances of classes. For instance a Dog class may describe what dogs are like. <br /> <br /> All dogs have specific properties like height, weight, color. Dog also have methods like bark. My dog rover is a specific instance of the dog class.<br /> <br /> <br /> &lt;csharp&gt;// Instantiate Dog objects<br /> // Declare an instance of the Dog class<br /> Dog firstDog;<br /> <br /> // Allocate memory for the dog object<br /> firstDog = new Dog();<br /> <br /> // Declare and Allocate in one like<br /> Dog secondDog = new Dog();&lt;/csharp&gt;<br /> <br /> The '''new''' keyword call the classes '''constructor''' which allocated memory on the stack for the object. <br /> <br /> access modifier restrictions <br /> <br /> {|-<br /> |public || No restrictions available to all members of the class.<br /> |-<br /> |private || Members marked private are only available to methods of that class.<br /> |-<br /> |protected || Members marked protected are available to methods of thay class and of classes dreived from that class.<br /> |-<br /> |internal ||Members marked as internal are available to any class within that classes assembly.<br /> |-<br /> |protected internal ||Same as protected and internal<br /> |}<br /> <br /> ==Chair Class==<br /> ===Fields===<br /> * int Height<br /> * int NumLegs<br /> * bool HasBack<br /> * bool HeightAdjustable<br /> <br /> ===Methods===<br /> <br /> * RaiseHeight<br /> * LowerHeight<br /> <br /> ===Chair Class UML===<br /> [[Image:ChairSimpleUML.png]]<br /> <br /> In class do phone class.<br /> <br /> ==Dog Class==<br /> ===Fields===<br /> Microsoft has started call ing public variables fields<br /> <br /> * string Name<br /> * int Age<br /> * int Weight<br /> * string BarkSound<br /> <br /> ===Methods===<br /> <br /> * Bark<br /> * Eat<br /> <br /> ===Dog Class UML===<br /> <br /> [[Image:DogSimpleUML.png]]<br /> <br /> ==Constructors==<br /> <br /> A classes constructor is the method that is run when an instance of the class is created. If you do not provide a constructor the complier provides one for you. The constructor is used to initiate all member properties. Unlike intrinsic types variables that are not initialized will be set to 0 or &quot;&quot; or null by the compiler in the default constructor.<br /> <br /> The constructor allows you to set default values for the properties of the class. If you do not provide a constructor then a default constructor will be provided. The default constructor will initialize all of the properites in the class to empty/zero/null values.<br /> <br /> constructor example<br /> <br /> &lt;csharp&gt;public class Dog<br /> {<br /> public Dog()<br /> {<br /> //constructor code<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> Simple Dog class with constructor<br /> <br /> &lt;csharp&gt;//Dog simple class definition<br /> public class Dog<br /> {<br /> public string Name; // the dog's name<br /> public int Age; // the dog's age<br /> public int Weight; // the dog's weight<br /> public string BarkSound; // the sound of the dog's bark<br /> <br /> public Dog()<br /> {<br /> BarkSound = &quot;Woof!!!&quot;;<br /> }<br /> <br /> public void Bark() { <br /> //put bark code here<br /> }<br /> public void Eat() {<br /> //put eat code here <br /> }<br /> }&lt;/csharp&gt;<br /> <br /> Console Example [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class4/dog1/Dog.cs Dog.cs] &lt;br /&gt;<br /> <br /> ==In Class==<br /> <br /> Make and compile a Cat class with a test class.<br /> *Draw UML for the Cat Class<br /> *Write test class<br /> *Compile and test test class<br /> *Make Dog class<br /> *Test Dog class with test class<br /> <br /> ==OverLoading Constructors==<br /> <br /> Overloading a constructor allows object creation to happen in different ways with different parameters. The class can be overloaded to accept different parameters but each constructor method must have a unique parameter signature.<br /> Dog class with overloaded constructor<br /> <br /> &lt;csharp&gt;//Dog overloaded class definition<br /> public class Dog<br /> {<br /> public string Name; // the dog's name<br /> public int Age; // the dog's age<br /> public int Weight; // the dog's weight<br /> public string BarkSound; // the sound of the dog's bark<br /> <br /> public Dog()<br /> {<br /> BarkSound = &quot;Woof!!!&quot;;<br /> }<br /> public Dog(string newName)<br /> {<br /> Name = newName;<br /> BarkSound = &quot;Woof!!!&quot;;<br /> }<br /> public Dog(string newName, string newBarkSound )<br /> {<br /> Name = newName;<br /> BarkSound = newBarkSound;<br /> }<br /> <br /> public void Bark() { <br /> //put bark code here<br /> }<br /> public void Eat() {<br /> //put eat code here <br /> }<br /> public string About() {<br /> string strAbout = &quot;&quot;;<br /> strAbout += this.Name;<br /> strAbout += &quot; &quot; + this.Age;<br /> strAbout += &quot; &quot; + this.Weight;<br /> strAbout += &quot; &quot; + this.BarkSound;<br /> return strAbout;<br /> }<br /> <br /> }<br /> <br /> <br /> }&lt;/csharp&gt; <br /> <br /> Console Example [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class4/dogOverload.cs dogOverload.cs]<br /> <br /> ==HomeWork==<br /> <br /> 2 own classes 1 course class<br /> <br /> Build two of your own classes that describes some real world objects then build a test class to demonstrate how your class works. Your own class should have properties, methods, and constructors.<br /> <br /> The classes should be in the same visual studio project. The use the program class to create new instances of your classes and set properties and call methods. Use Console.Write to show how properties have been changed and the results of calling the methods.<br /> <br /> 3 pts. It can be anything be creative.<br /> 2 pts. Create the course class UML below.<br /> <br /> [[Image:CourseUML-VS.JPG]]<br /> [[Image:CousreUML-Dia.png]]<br /> <br /> ==Links==<br /> * [http://www.csharphelp.com/archives/archive135.html Operator Overloading In C#]<br /> <br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> <br /> namespace Cat<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Hello I'm a cat program&quot;);<br /> <br /> Cat punkin = new Cat();<br /> Cat bella = new Cat();<br /> <br /> punkin.NAME = &quot;punkin&quot;;<br /> punkin.WEIGHT = 5;<br /> <br /> bella.NAME = &quot;bella&quot;;<br /> bella.WEIGHT = 20;<br /> <br /> Console.WriteLine(punkin.About());<br /> <br /> punkin.Meow();<br /> punkin.Eat();<br /> <br /> Console.WriteLine(punkin.About());<br /> <br /> Console.WriteLine(bella.About());<br /> <br /> Console.ReadKey();<br /> }<br /> }<br /> <br /> public class Cat<br /> {<br /> <br /> //Properties<br /> public string NAME;<br /> public int AGE;<br /> public int WEIGHT;<br /> public bool isUGLY;<br /> public bool isStoopid;<br /> <br /> public string MEOWSOUND;<br /> <br /> //Constructor<br /> public Cat()<br /> {<br /> //set seom default values<br /> this.NAME = &quot;some cats name&quot;;<br /> this.AGE = 0;<br /> this.WEIGHT = 47;<br /> this.isUGLY = true;<br /> this.isStoopid = true;<br /> <br /> this.MEOWSOUND = &quot;Meow!!!!&quot;;<br /> }<br /> <br /> //Methods<br /> public void Meow()<br /> {<br /> //write meow sound to the console<br /> Console.WriteLine(this.MEOWSOUND);<br /> }<br /> <br /> public void Eat()<br /> {<br /> this.WEIGHT++;<br /> Console.WriteLine(&quot;MMMMMM yummy&quot;);<br /> }<br /> <br /> public string About()<br /> {<br /> string strAbout = &quot;&quot;;<br /> strAbout += this.NAME;<br /> strAbout += &quot;\n&quot; + this.WEIGHT;<br /> strAbout += &quot;\n&quot; + this.AGE;<br /> if (this.isUGLY)<br /> {<br /> strAbout += &quot;\nI'm an Ugly cat&quot;;<br /> }<br /> else<br /> {<br /> strAbout += &quot;\nI'm an nice looking cat&quot;;<br /> }<br /> <br /> if (this.isStoopid)<br /> {<br /> strAbout += &quot;\nI'm an stoopid cat&quot;;<br /> }<br /> <br /> return strAbout;<br /> }<br /> <br /> }<br /> <br /> }<br /> &lt;/csharp&gt;<br /> <br /> ==Video==<br /> &lt;html&gt;<br /> &lt;script type='text/javascript' src='http://iam.colum.edu/videotutorials/mediaplayer-5.2/swfobject.js'&gt;&lt;/script&gt; <br /> &lt;div id='mediaspace2'&gt;This text will be replaced&lt;/div&gt; <br /> &lt;script type='text/javascript'&gt;<br /> var so = new SWFObject('http://iam.colum.edu/videotutorials/mediaplayer-5.2/player.swf','mpl','800','600','9');so.addParam('allowfullscreen','true')<br /> ;so.addParam('allowscriptaccess','always');<br /> so.addParam('wmode','opaque');<br /> so.addVariable('file','http://iam.colum.edu/screenz/FA13/OOP_MT/OOP_Class4_MT_Tue/OOP_Class4_MT_Tue.mp4');<br /> so.addVariable('autostart','false');<br /> so.write('mediaspace2');<br /> <br /> &lt;/script&gt;<br /> <br /> &lt;/html&gt;</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class4&diff=21745 OOP Class4 2013-09-26T18:17:38Z <p>Cameron.Cintron: /* Links */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> =Classes and Objects=<br /> ==Objects==<br /> <br /> Object-oriented programs are made up of objects. <br /> :&quot;An object packages both data and the procedures that operate on that data. The procedures are typically called methods or operations. An object performs an operation when it receives a request(or message) from a client. &quot; - Design Patterns Addison Wesley<br /> Reasons for organizing code into Classes and Objects<br /> <br /> * avoid spaghetti<br /> * organize code into logical sections<br /> * simplify program designs<br /> * reuse<br /> <br /> Classes are sections of code that describe real world objects. Classes define what '''properties''' and '''methods''' an object contains. <br /> Properties<br /> :define data members of classes. Nouns<br /> <br /> Methods <br /> :define what classes can do. Verbs<br /> <br /> ===Abstraction===<br /> <br /> Humans are always abstracting and naming objects. It is how we identify things. Objects are identified by two things: properties(what the have) and methods (what they do).<br /> <br /> Classes are used to define objects. <br /> <br /> The hardest part about object oriented programming is choosing how to build and implement these abstractions. There are many factors that affect these decisions. It can often be very difficult to find a balance between all of the factors.<br /> <br /> * granularity<br /> :the size and acuracy of you abstraction<br /> * re usability<br /> :simpler objects are more reusable<br /> * flexibility<br /> :specialized objects are often less flexible<br /> * performance<br /> * portability<br /> <br /> ==Encapsulation==<br /> <br /> Allows us to use objects with out completely understanding how everything inside the object works. Encapsulation also allows the internal state of objects to be changed easily without affecting other objects or interfaces. For example you don't need to know how the phone system works in order to use a telephone. All you really need to know to use the phone system is how to dial a phone<br /> Classes<br /> <br /> Classes are used to create objects.<br /> a simple example of class syntax in c#<br /> <br /> &lt;csharp&gt;public class Dog{ }&lt;/csharp&gt;<br /> <br /> class syntax full<br /> <br /> [attributes] [access modifiers} class identifier [:base class]<br /> {class body}<br /> <br /> Objects are instances of classes. For instance a Dog class may describe what dogs are like. <br /> <br /> All dogs have specific properties like height, weight, color. Dog also have methods like bark. My dog rover is a specific instance of the dog class.<br /> <br /> <br /> &lt;csharp&gt;// Instantiate Dog objects<br /> // Declare an instance of the Dog class<br /> Dog firstDog;<br /> <br /> // Allocate memory for the dog object<br /> firstDog = new Dog();<br /> <br /> // Declare and Allocate in one like<br /> Dog secondDog = new Dog();&lt;/csharp&gt;<br /> <br /> The '''new''' keyword call the classes '''constructor''' which allocated memory on the stack for the object. <br /> <br /> access modifier restrictions <br /> <br /> {|-<br /> |public || No restrictions available to all members of the class.<br /> |-<br /> |private || Members marked private are only available to methods of that class.<br /> |-<br /> |protected || Members marked protected are available to methods of thay class and of classes dreived from that class.<br /> |-<br /> |internal ||Members marked as internal are available to any class within that classes assembly.<br /> |-<br /> |protected internal ||Same as protected and internal<br /> |}<br /> <br /> ==Chair Class==<br /> ===Fields===<br /> * int Height<br /> * int NumLegs<br /> * bool HasBack<br /> * bool HeightAdjustable<br /> <br /> ===Methods===<br /> <br /> * RaiseHeight<br /> * LowerHeight<br /> <br /> ===Chair Class UML===<br /> [[Image:ChairSimpleUML.png]]<br /> <br /> In class do phone class.<br /> <br /> ==Dog Class==<br /> ===Fields===<br /> Microsoft has started call ing public variables fields<br /> <br /> * string Name<br /> * int Age<br /> * int Weight<br /> * string BarkSound<br /> <br /> ===Methods===<br /> <br /> * Bark<br /> * Eat<br /> <br /> ===Dog Class UML===<br /> <br /> [[Image:DogSimpleUML.png]]<br /> <br /> ==Constructors==<br /> <br /> A classes constructor is the method that is run when an instance of the class is created. If you do not provide a constructor the complier provides one for you. The constructor is used to initiate all member properties. Unlike intrinsic types variables that are not initialized will be set to 0 or &quot;&quot; or null by the compiler in the default constructor.<br /> <br /> The constructor allows you to set default values for the properties of the class. If you do not provide a constructor then a default constructor will be provided. The default constructor will initialize all of the properites in the class to empty/zero/null values.<br /> <br /> constructor example<br /> <br /> &lt;csharp&gt;public class Dog<br /> {<br /> public Dog()<br /> {<br /> //constructor code<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> Simple Dog class with constructor<br /> <br /> &lt;csharp&gt;//Dog simple class definition<br /> public class Dog<br /> {<br /> public string Name; // the dog's name<br /> public int Age; // the dog's age<br /> public int Weight; // the dog's weight<br /> public string BarkSound; // the sound of the dog's bark<br /> <br /> public Dog()<br /> {<br /> BarkSound = &quot;Woof!!!&quot;;<br /> }<br /> <br /> public void Bark() { <br /> //put bark code here<br /> }<br /> public void Eat() {<br /> //put eat code here <br /> }<br /> }&lt;/csharp&gt;<br /> <br /> Console Example [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class4/dog1/Dog.cs Dog.cs] &lt;br /&gt;<br /> <br /> ==In Class==<br /> <br /> Make and compile a Cat class with a test class.<br /> *Draw UML for the Cat Class<br /> *Write test class<br /> *Compile and test test class<br /> *Make Dog class<br /> *Test Dog class with test class<br /> <br /> ==OverLoading Constructors==<br /> <br /> Overloading a constructor allows object creation to happen in different ways with different parameters. The class can be overloaded to accept different parameters but each constructor method must have a unique parameter signature.<br /> Dog class with overloaded constructor<br /> <br /> &lt;csharp&gt;//Dog overloaded class definition<br /> public class Dog<br /> {<br /> public string Name; // the dog's name<br /> public int Age; // the dog's age<br /> public int Weight; // the dog's weight<br /> public string BarkSound; // the sound of the dog's bark<br /> <br /> public Dog()<br /> {<br /> BarkSound = &quot;Woof!!!&quot;;<br /> }<br /> public Dog(string newName)<br /> {<br /> Name = newName;<br /> BarkSound = &quot;Woof!!!&quot;;<br /> }<br /> public Dog(string newName, string newBarkSound )<br /> {<br /> Name = newName;<br /> BarkSound = newBarkSound;<br /> }<br /> <br /> public void Bark() { <br /> //put bark code here<br /> }<br /> public void Eat() {<br /> //put eat code here <br /> }<br /> public string About() {<br /> string strAbout = &quot;&quot;;<br /> strAbout += this.Name;<br /> strAbout += &quot; &quot; + this.Age;<br /> strAbout += &quot; &quot; + this.Weight;<br /> strAbout += &quot; &quot; + this.BarkSound;<br /> return strAbout;<br /> }<br /> <br /> }<br /> <br /> <br /> }&lt;/csharp&gt; <br /> <br /> Console Example [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class4/dogOverload.cs dogOverload.cs]<br /> <br /> ==HomeWork==<br /> <br /> 2 own classes 1 course class<br /> <br /> Build two of your own classes that describes some real world objects then build a test class to demonstrate how your class works. Your own class should have properties, methods, and constructors.<br /> <br /> The classes should be in the same visual studio project. The use the program class to create new instances of your classes and set properties and call methods. Use Console.Write to show how properties have been changed and the results of calling the methods.<br /> <br /> 3 pts. It can be anything be creative.<br /> 2 pts. Create the course class UML below.<br /> <br /> [[Image:CourseUML-VS.JPG]]<br /> [[Image:CousreUML-Dia.png]]<br /> <br /> ==Links==<br /> * [http://www.csharphelp.com/archives/archive135.html Operator Overloading In C#]<br /> <br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> <br /> namespace Cat<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Hello I'm a cat program&quot;);<br /> <br /> Cat punkin = new Cat();<br /> Cat bella = new Cat();<br /> <br /> punkin.NAME = &quot;punkin&quot;;<br /> punkin.WEIGHT = 5;<br /> <br /> bella.NAME = &quot;bella&quot;;<br /> bella.WEIGHT = 20;<br /> <br /> Console.WriteLine(punkin.About());<br /> <br /> punkin.Meow();<br /> punkin.Eat();<br /> <br /> Console.WriteLine(punkin.About());<br /> <br /> Console.WriteLine(bella.About());<br /> <br /> Console.ReadKey();<br /> }<br /> }<br /> <br /> public class Cat<br /> {<br /> <br /> //Properties<br /> public string NAME;<br /> public int AGE;<br /> public int WEIGHT;<br /> public bool isUGLY;<br /> public bool isStoopid;<br /> <br /> public string MEOWSOUND;<br /> <br /> //Constructor<br /> public Cat()<br /> {<br /> //set seom default values<br /> this.NAME = &quot;some cats name&quot;;<br /> this.AGE = 0;<br /> this.WEIGHT = 47;<br /> this.isUGLY = true;<br /> this.isStoopid = true;<br /> <br /> this.MEOWSOUND = &quot;Meow!!!!&quot;;<br /> }<br /> <br /> //Methods<br /> public void Meow()<br /> {<br /> //write meow sound to the console<br /> Console.WriteLine(this.MEOWSOUND);<br /> }<br /> <br /> public void Eat()<br /> {<br /> this.WEIGHT++;<br /> Console.WriteLine(&quot;MMMMMM yummy&quot;);<br /> }<br /> <br /> public string About()<br /> {<br /> string strAbout = &quot;&quot;;<br /> strAbout += this.NAME;<br /> strAbout += &quot;\n&quot; + this.WEIGHT;<br /> strAbout += &quot;\n&quot; + this.AGE;<br /> if (this.isUGLY)<br /> {<br /> strAbout += &quot;\nI'm an Ugly cat&quot;;<br /> }<br /> else<br /> {<br /> strAbout += &quot;\nI'm an nice looking cat&quot;;<br /> }<br /> <br /> if (this.isStoopid)<br /> {<br /> strAbout += &quot;\nI'm an stoopid cat&quot;;<br /> }<br /> <br /> return strAbout;<br /> }<br /> <br /> }<br /> <br /> }<br /> &lt;/csharp&gt;<br /> <br /> ==Video==<br /> &lt;html&gt;<br /> &lt;script type='text/javascript' src='http://iam.colum.edu/videotutorials/mediaplayer-5.2/swfobject.js'&gt;&lt;/script&gt; <br /> &lt;div id='mediaspace2'&gt;This text will be replaced&lt;/div&gt; <br /> &lt;script type='text/javascript'&gt;<br /> var so = new SWFObject('http://iam.colum.edu/videotutorials/mediaplayer-5.2/player.swf','mpl','800','600','9');so.addParam('allowfullscreen','true')<br /> ;so.addParam('allowscriptaccess','always');<br /> so.addParam('wmode','opaque');<br /> so.addVariable('file','http://iam.colum.edu/screenz/FA13/OOP_MT/OOP_Class3_MT_Tue/OOP_Class3_MT_Tue.mp4');<br /> so.addVariable('autostart','false');<br /> so.write('mediaspace2');<br /> <br /> &lt;/script&gt;<br /> <br /> &lt;/html&gt;</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class2&diff=21744 OOP Class2 2013-09-19T18:23:49Z <p>Cameron.Cintron: /* Video */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> ==Posting home work and website==<br /> <br /> =C# fundamentals=<br /> <br /> Questions from week 1 reading.<br /> discussion<br /> <br /> Some pages comparing c# to other languages<br /> <br /> A Comparative Overview of C# http://genamics.com/developer/csharp_comparative.htm<br /> <br /> C# and Java: Comparing Programming Languages http://msdn.microsoft.com/en-us/library/ms836794.aspx<br /> <br /> ==Terms==<br /> <br /> CLR<br /> :Common Language Runtime<br /> namespace<br /> :organizing classes with hierarchy <br /> keyword<br /> :reserved system word<br /> MSIL<br /> :MicroSoft Intermediary Language<br /> JIT<br /> :Just In Time compilation @ first run<br /> <br /> ==Everything is an Object==<br /> In c# everything is an object. And all objects inherit from the object class.<br /> <br /> [http://quickstarts.asp.net/QuickStartv20/util/classbrowser.aspx See object in the classbrowser]<br /> <br /> Since all objects inherit from the object class they all have some the basic functionality like a method called ToString();<br /> <br /> [http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class2/FromMono See the source for object.cs from mono] <br /> <br /> <br /> ==Basic Data Types==<br /> <br /> C# is a strongly typed language. This means every object in C# must be declared to be of a specific type. All of c# basic varible type inherit from [http://msdn2.microsoft.com/en-us/library/system.object.aspx System.Object]<br /> <br /> {{.NET Data Types}}<br /> <br /> Variables must be declared with an identifier and then initialized.<br /> <br /> ===Declaration===<br /> <br /> Declaration sets aside a named section of memory the is the proper size to hold the declared type. At this point the variable contains nothing.<br /> <br /> &lt;csharp&gt;// declare a variable<br /> int firstInt; //declares a vaiable of type int<br /> string myString; //declares a vaiable of type string&lt;/csharp&gt;<br /> <br /> ===Initialization===<br /> <br /> Initialization actually sets the variables value<br /> <br /> &lt;csharp&gt;// initialize the variable<br /> firstInt = 1;<br /> myString = &quot;Hello!&quot;;&lt;/csharp&gt;<br /> <br /> Initialization uses the assignment operator to set the value of a variable<br /> <br /> ===Assignment===<br /> The Assignment '''operator''' in c# is the '=' sign. You can assign variables like this...<br /> <br /> ==Assignment==<br /> The Assignment operator in c# is the '=' sign. You can assign variables like this...<br /> We'll learn more about operators later.<br /> <br /> other ways to do it<br /> <br /> &lt;csharp&gt;// declare some variables<br /> int secondInt, thirdInt, fourthInt;<br /> secondInt = 2;<br /> thirdInt = 3;<br /> fourthInt = 4;<br /> <br /> //declare and initialize variables in one line<br /> int myNegativeInt = -2147483648;&lt;/csharp&gt;<br /> <br /> In c# variables cannot be used unil they are initalized.<br /> For example<br /> <br /> &lt;csharp&gt;int UsedBeforeInit;<br /> Console.WriteLine(UsedBeforeInit);&lt;/csharp&gt;<br /> <br /> will produce<br /> <br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> <br /> ==Compiler Errors==<br /> error<br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> file Line .Net Framework error # and description<br /> <br /> <br /> <br /> [[Csharp warning CS0168: The variable 'NeverUsed' is declared but never used]]<br /> <br /> <br /> <br /> <br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit.cs UsedBeforeInit.cs] - example of misused variable&lt;br /&gt;<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit_Fixed.cs UsedBeforeInit_Fixed.cs] - all beter now source&lt;br /&gt;<br /> <br /> More examples of built in types<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/csharpfundamentals/1x1.cs 1x1.cs] C# intrinsic types from Learn-C-Sharp.<br /> variable.aspx - example from book aspx page View Source<br /> variable2.aspx = example from book errors View Source<br /> <br /> ==Variable Names==<br /> <br /> Variable should be named with meaningful names.<br /> <br /> for exmaple <br /> :z = x * y;<br /> <br /> does not convey any meaning<br /> <br /> but<br /> :distance = speed * time;<br /> <br /> does convey meaning.<br /> If varibales are named properly it can make your code mush easier to read.<br /> <br /> ==Naming conventions==<br /> Name variables intelligently.&lt;br&gt;<br /> Name variables with names that have meaning.&lt;br&gt;<br /> <br /> ===Hungarian Notation===<br /> Hungarian notation id a popular notation system used be many C, C++ and VB programmers. It was originally devised in Charles Simonyi's doctoral thesis, &quot;Meta-Programming: A Software Production Method.&quot; Hungarian notation specifies that a prefix be added to each variable that indicated that variables type. It also specifies sometimes adding a suffice to clarify variables meaning. In the early 1980's Microsoft adopted this notation system.<br /> <br /> <br /> ie... intHitCounter, intHitsPerMonthMax <br /> <br /> [http://msdn.microsoft.com/en-us/library/aa260976(VS.60).aspx Hungarian Notation - Charles Simonyi Microsoft]<br /> <br /> http://msdn.microsoft.com/en-us/library/ms229045.aspx<br /> <br /> '''PascalNotation'''<br /> Capitalize first Letter and then the first letter on each word. &lt;br&gt;<br /> ie... PascalNotation, IntVarName<br /> <br /> Use on method names method names.<br /> <br /> '''camelNotation'''<br /> Lower case first letter and then capitalize the first letter of each word&lt;br&gt;<br /> ie... camelNotation, intVarName<br /> <br /> use for variable names<br /> <br /> Other Coding Techniques and practices&lt;br&gt;<br /> [http://msdn.microsoft.com/en-us/library/ms229002.aspx .NET Framework Developer's Guide<br /> Guidelines for Names]&lt;br&gt;<br /> [http://www-106.ibm.com/developerworks/eserver/articles/hook_duttaC.html?ca=dgr-lnxw06BestC IBM Best Practices for Programming in C]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html GNU Coding Standards]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html#Names GNU Naming conventions]&lt;br&gt;<br /> More Types<br /> <br /> ==Operators==<br /> <br /> ECMA-334 Operators and punctuators<br /> <br /> C# uses the equals = sign for Assignment<br /> <br /> int myVar = 15; //sets the value of myVar to 15<br /> <br /> ===Mathematical Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |+ ||addition<br /> |-<br /> |- || subtraction<br /> |-<br /> |* || multiplication<br /> |-<br /> |/ || division<br /> |-<br /> |% || modulus remainder Ask Dr.Math What is Modulus?<br /> |}<br /> <br /> ===Increment Decrement Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |++ || increment same as foo = foo + 1<br /> |-<br /> | -- || decrement same as foo = foo - 1<br /> |-<br /> |+= || calculate and reassign addition<br /> |-<br /> | -= || calculate and reassign subtraction<br /> |-<br /> |*= || calculate and reassign multiplication<br /> |-<br /> |/= || calculate and reassign division<br /> |-<br /> |%= || calculate and reassign modulus<br /> |-<br /> |y= x++ || assignment prefix y is assigned to x and then x in incremented<br /> |-<br /> |y= ++x || assignment postfix x is incremented and then assigned to y<br /> |}<br /> <br /> ===Operator Precedence===<br /> Evaluated First<br /> <br /> * ++,--,unary-<br /> * *,/,%<br /> * +,-<br /> <br /> Evaluated Last<br /> <br /> * =,+=,-=,*=,etc<br /> <br /> <br /> {{csharp strings}}<br /> {{csharp string functions}}<br /> <br /> ==Short Assignment==<br /> Short in class Assignment<br /> In class assignment 10-15 mins<br /> Build a c# console app (remember to take a top down aproach start small with something you know maybe start with hello world)<br /> * Declare and initialize two integers<br /> * Display their values using Console.WriteLine<br /> * Declare a third integer and initialize it with the sum of the first two integers<br /> * Output the value of the third integer<br /> <br /> <br /> Top down development with comments [http://iam.colum.edu/oop/classsource/class2/topdown.aspx topdown.aspx]<br /> <br /> Fully implemented Console adding program [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/add.cs add.cs]<br /> <br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> <br /> namespace Hello<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Super Cool Calculatorizer&quot;);<br /> <br /> //Declare two variables<br /> int intOne;<br /> int intTwo;<br /> int intSum;<br /> <br /> //intialize the two variables<br /> intOne = 47;<br /> intTwo = 2;<br /> <br /> //Lets test the values<br /> Console.Write(&quot;Enter a integer: &quot;);<br /> intOne = int.Parse(Console.ReadLine()); //set the value of intOne <br /> //to what was typed in the console<br /> Console.Write(&quot;Enter another integer: &quot;);<br /> intTwo = int.Parse(Console.ReadLine()); //int.Parse attempts to parse a string<br /> //and convert it to an int<br /> <br /> intSum = intOne + intTwo;<br /> <br /> Console.WriteLine(&quot;intTwo + intTwo = &quot; + intSum);<br /> <br /> Console.ReadKey();<br /> <br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> ==Constants==<br /> <br /> Constants are datatypes that will be assigned a value that will be constant thought the executing of the code. You cannot change constants once they have been assigned a value.<br /> syntax<br /> <br /> &lt;csharp&gt;const type identifier = value;&lt;/csharp&gt;<br /> <br /> <br /> example<br /> <br /> &lt;csharp&gt;const int freezingPoint = 32;<br /> const int freezingPointMetric = 0;<br /> const float pi = 3.141592&lt;/csharp&gt;<br /> <br /> <br /> [[OOP Arrays]]<br /> {{csharp arrays}}<br /> <br /> <br /> ==Simple Branching==<br /> <br /> ===if===<br /> syntax<br /> <br /> &lt;csharp&gt;if (expression)<br /> // statement<br /> <br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> else {<br /> // statements<br /> }&lt;/csharp&gt;<br /> <br /> ==HomeWork==<br /> *Learning c#<br /> *Chapter 5, Chapter 6<br /> <br /> <br /> Create a simple text game that asks three questions and sets three variables. There should be a fourth variable that counts the number of correct answers. The program should run in the console and use:<br /> <br /> *Console.WriteLine<br /> *Console.ReadLine<br /> *ints, strings and ifs<br /> <br /> Analysis of Homework Project<br /> *On very structured programs like this one analysis is quite easy<br /> ** Start by identifying the steps<br /> ** Add [http://en.wikipedia.org/wiki/Pseudocode Pseudocode] as c# comments for each step<br /> ** Fill in the real syntax for each step and compile each time to make sure nothing breaks (I like to call this baby steps and I like to use this technique whenever I'm trying to implement something that is completely new to me)<br /> <br /> The pseudocode might look something like<br /> &lt;csharp&gt;using System;<br /> namespace HelloVariables<br /> {<br /> class ThreeQuestions<br /> {<br /> public static void Main()<br /> {<br /> Console.WriteLine(&quot;3 Questions&quot;);<br /> //A simple game that asks three questions and checks the answers. If the question is answered correctly we will award 1 point<br /> <br /> //Declare Variables<br /> <br /> //Ask Question 1<br /> <br /> //Read Answer<br /> <br /> //Check Answer and add 1 to points is correct<br /> <br /> //Repeat with Questions 2 and 3<br /> <br /> //Display Percent Correct<br /> <br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> ==Video==<br /> &lt;html&gt;<br /> &lt;script type='text/javascript' src='http://iam.colum.edu/videotutorials/mediaplayer-5.2/swfobject.js'&gt;&lt;/script&gt; <br /> &lt;div id='mediaspace2'&gt;This text will be replaced&lt;/div&gt; <br /> &lt;script type='text/javascript'&gt;<br /> var so = new SWFObject('http://iam.colum.edu/videotutorials/mediaplayer-5.2/player.swf','mpl','800','600','9');so.addParam('allowfullscreen','true')<br /> ;so.addParam('allowscriptaccess','always');<br /> so.addParam('wmode','opaque');<br /> so.addVariable('file','http://iam.colum.edu/screenz/FA13/OOP_MT/OOP_Week_2/OOP_Week_2.mp4');<br /> so.addVariable('autostart','false');<br /> so.write('mediaspace2');<br /> <br /> &lt;/script&gt;<br /> <br /> &lt;/html&gt;</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class3&diff=21743 OOP Class3 2013-09-19T18:21:34Z <p>Cameron.Cintron: /* Home work */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> <br /> ==Conversion Casting==<br /> Casting is the process of converting form one type of object to another, There are two Conversion types in C# implicit and explicit. Implicit conversion is handled by the compiler and requires no extra work. Implicit conversion is only possible if the new data type can hold the old data type with out any data loss. explicit conversion forces on datatype into another even if it doesn't fit. It is up to the programmer to define explicit casts.<br /> <br /> ===implicit conversion===<br /> <br /> &lt;csharp&gt;int intNumber = 1000;<br /> long lngNumber;<br /> lngNumber = intNumber;<br /> <br /> int Number1= 6;<br /> int Number2= 5;<br /> int Number3 = Number1 / Number2;<br /> //Number3 == 1 NOT 1.2 because Number3 is an int<br /> &lt;/csharp&gt;<br /> <br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class2/implicitConversion.cs implicitConversion.cs]<br /> <br /> ===explicit conversion===<br /> <br /> &lt;csharp&gt;long lngNumber = 1000;<br /> int intNumber;<br /> intNumber = (int)lngNumber;<br /> <br /> int Number1= 6;<br /> int Number2= 5;<br /> double Number3 = (double)Number1 / (double)Number2;<br /> //Number3 == 1.2&lt;/csharp&gt;<br /> <br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/explicitConversion.cs explicitConversion.cs]<br /> <br /> Some types cannot be cast from one type to another but the Framework has it's ows Conversion Class.<br /> [http://iam.colum.edu/quickstart/util/classbrowser.aspx?assembly=mscorlib,%20Version=2.0.0.0,%20Culture=neutral,%20PublicKeyToken=b77a5c561934e089&amp;namespace=System&amp;class=Convert Convert ]<br /> <br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/ConvertClass.cs ConvertClass.cs] and Emample of using the convert class to convert an interger to a boolean<br /> <br /> =Operators=<br /> [http://www.jaggersoft.com/csharp_standard/9.4.5.htm ECMA-334 Operators and punctuators]<br /> <br /> <br /> ==Assignment==<br /> The Assigment operator in c# is the '=' sign. You can assign variables like this...<br /> <br /> &lt;csharp&gt;int myVar; //declare varible of type int called myVar<br /> myVar = 15; //assign myVar the value of 15 using the '=' sign&lt;/csharp&gt;<br /> <br /> ==Comparison Operators==<br /> {|-<br /> |Operator || Description<br /> |- <br /> |== || Equality<br /> |- <br /> |&lt; || Less Than<br /> |- <br /> |&lt;= || Less than or equal to<br /> |- <br /> |&gt; || Greater than<br /> |- <br /> |&gt;= ||Greater than or equal to <br /> |- <br /> |!= ||Inequality<br /> |}<br /> <br /> ==Logical Operators==<br /> {|-<br /> |Operator || Description <br /> |- <br /> |&amp;&amp; || Logical AND<br /> |- <br /> | II || Logical OR (note the II are really pipes)<br /> |- <br /> |! || Logical NOT<br /> |}<br /> <br /> ==Boolean Expressions==<br /> Logical operators usually work on bollean expressions. Boolean expressions are is a statement that evaluates to true of false<br /> <br /> (1 &lt; 2)<br /> or<br /> (y == x)<br /> <br /> Boolean expressions are often grouped with logical operator to combine comparisons<br /> <br /> (x &gt; 0) &amp;&amp; (x &lt;100) //x is greater than 0 and less than 100<br /> <br /> (x &lt; 0) || (x &gt;100) //x is less than zero or x is greater than 100<br /> <br /> ==Logical operator Precedence==<br /> <br /> # ! (NOT)<br /> # &amp;&amp; (AND) <br /> # || (OR)<br /> <br /> =Branching=<br /> evil goto - I won't show it figure it out on your own...<br /> <br /> * if<br /> * switch<br /> <br /> ==Looping==<br /> <br /> * for<br /> * while<br /> * do... while<br /> * foreach<br /> <br /> ==Branching Statements==<br /> ===if===<br /> syntax<br /> <br /> &lt;csharp&gt;if (expression)<br /> // statement<br /> <br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> else {<br /> // statements<br /> }&lt;/csharp&gt;<br /> <br /> <br /> About braces and indenting. I usually use BSD/Allman Style.&lt;br /&gt;<br /> [http://jargon.watson-net.com/section.asp Jargon File]&lt;br /&gt; <br /> [http://jargon.watson-net.com/jargon.asp?w=indent+style indent style n.]&lt;br /&gt;<br /> [http://komputado.com/eseoj/1tbs.htm The One True Brace Style]&lt;br /&gt;<br /> <br /> Console Input<br /> There are several ways to get data into your program. One of the simplest is to have someone type it into the console.<br /> The frame work supports Console.ReadLine() this method reads on line from the input of the console.&lt;br /&gt;<br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class3/EchoOnce.cs EchoOnce.cs]&lt;br /&gt;<br /> Another popular way to get data into your program is to send it in as an argument when the program is run.&lt;br /&gt;<br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class3/HelloName.cs HelloName.cs]&lt;br /&gt;<br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class3/HelloNameSafe.cs HelloNameSafe.cs]&lt;br /&gt;<br /> <br /> if example [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class3/IfSelection.cs IfSelection.cs - source]<br /> <br /> The following code uses a bunch of operator and if statements to do some basic sanity checks. Analyze it and try to predict the output&lt;br&gt;<br /> sanityCheck.cs - source<br /> <br /> ===switch===<br /> syntax<br /> <br /> switch (expression)<br /> {<br /> case constant-expression:<br /> statement<br /> jump-statement<br /> [default: statement]<br /> }<br /> <br /> <br /> example 1<br /> <br /> &lt;csharp&gt;// switch with integer type<br /> switch (myInt)<br /> {<br /> case 1:<br /> Console.WriteLine(&quot;Your number is {0}.&quot;, myInt);<br /> break;<br /> case 2:<br /> Console.WriteLine(&quot;Your number is {0}.&quot;, myInt);<br /> break;<br /> case 3:<br /> Console.WriteLine(&quot;Your number is {0}.&quot;, myInt);<br /> break;<br /> default:<br /> Console.WriteLine(&quot;Your number {0} is not between 1 and 3.&quot;, myInt);<br /> break;<br /> }&lt;/csharp&gt;<br /> <br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class3/Switch1to3.cs Switch1to3.cs]&lt;br /&gt;<br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class3/Switch1to3WithTryAndCatch.cs Switch1to3WithTryAndCatch.cs]&lt;br /&gt;<br /> <br /> fall though and goto case<br /> <br /> &lt;csharp&gt;// fall though and goto case<br /> switch (myChoice)<br /> {<br /> case &quot;NewLeft&quot;:<br /> Console.WriteLine(&quot;Newleft is voting Democratic.&quot;);<br /> goto case &quot;Democrat&quot;;<br /> case &quot;Democrat&quot;:<br /> Console.WriteLine(&quot;You voted Democratic.&quot;);<br /> break;<br /> case &quot;CompassionateRepublican&quot;:<br /> case &quot;Republican&quot;:<br /> Console.WriteLine(&quot;You voted Republican.&quot;);<br /> break;<br /> default:<br /> Console.WriteLine(&quot;Please vote....&quot;);<br /> break;<br /> }&lt;/csharp&gt;<br /> <br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class3/SwitchPolitics.cs SwitchPolitics.cs]&lt;br /&gt;<br /> <br /> ==Looping Statements==<br /> ===for===<br /> syntax<br /> <br /> for ([initializers]; [expression]; [iterators]) statement<br /> <br /> <br /> &lt;csharp&gt;for (int i=0; i &lt; 10; i++)<br /> {<br /> forOneResult += &quot;For Loop &quot; + i + &quot;&lt;br /&gt;&quot;;<br /> }&lt;/csharp&gt;<br /> <br /> Produces<br /> &lt;pre&gt;<br /> For Loop 0<br /> For Loop 1<br /> For Loop 2<br /> For Loop 3<br /> For Loop 4<br /> For Loop 5<br /> For Loop 6<br /> For Loop 7<br /> For Loop 8<br /> For Loop 9<br /> &lt;/pre&gt;<br /> &lt;csharp&gt;for (int i=0; i &lt; 20; i++)<br /> {<br /> if (i == 10)<br /> break;<br /> <br /> if (i % 2 == 0)<br /> continue;<br /> <br /> forTwoResult += &quot;For Loop &quot; + i + &quot;&lt;br /&gt;&quot;;<br /> }&lt;/csharp&gt;<br /> <br /> Produces<br /> &lt;pre&gt;<br /> For Loop 1<br /> For Loop 3<br /> For Loop 5<br /> For Loop 7<br /> For Loop 9<br /> &lt;/pre&gt;<br /> <br /> For loops can also be good to dynamically add or alter the contents or web controls. For example If I wanted a web control to have 100 items in it like this . I could use a for loop to add them here's an example<br /> <br /> /infod/jeff/classSource/class3/DynamicAddDropdown.aspx - source<br /> <br /> ===while===<br /> while syntax<br /> <br /> while (expression) statement<br /> <br /> &lt;csharp&gt;string whileLoopResult = &quot;&quot;;<br /> int MyInt = 0;<br /> <br /> while (MyInt &lt; 10)<br /> {<br /> Whileloopresult +=&quot;While Loop &quot; + MyInt + &quot;\n&quot;;<br /> MyInt++;<br /> }&lt;/csharp&gt;<br /> <br /> produces<br /> &lt;pre&gt;<br /> While Loop 0<br /> While Loop 1<br /> While Loop 2<br /> While Loop 3<br /> While Loop 4<br /> While Loop 5<br /> While Loop 6<br /> While Loop 7<br /> While Loop 8<br /> While Loop 9<br /> &lt;/pre&gt;<br /> <br /> ==do==<br /> do... while syntax<br /> <br /> do statement while (boolean-expression);<br /> <br /> <br /> &lt;csharp&gt;string doLoopResult = &quot;&quot;;<br /> int myIntDo = 0;<br /> <br /> do<br /> {<br /> doLoopResult +=&quot;do Loop &quot; + myIntDo + &quot;\n&quot;;<br /> myIntDo++;<br /> } while (myIntDo &lt; 10);&lt;/csharp&gt;<br /> <br /> produces<br /> &lt;pre&gt;<br /> do Loop 0<br /> do Loop 1<br /> do Loop 2<br /> do Loop 3<br /> do Loop 4<br /> do Loop 5<br /> do Loop 6<br /> do Loop 7<br /> do Loop 8<br /> do Loop 9<br /> &lt;/pre&gt;<br /> <br /> <br /> &lt;csharp&gt;string doLoopResult2 = &quot;&quot;;<br /> int myIntDo2 = 30;<br /> <br /> do<br /> {<br /> doLoopResult2 +=&quot;do Loop &quot; + myInt + &quot;\n&quot;;<br /> myIntDo2++;<br /> } while (myIntDo2 &lt; 10);&lt;/csharp&gt;<br /> <br /> produces<br /> do Loop 30<br /> <br /> ==for each==<br /> A for each loop requires and iterator.. more on this iterator thing later...<br /> <br /> &lt;csharp&gt;string[] names = {&quot;Cheryl&quot;, &quot;Joe&quot;, &quot;Matt&quot;, &quot;Robert&quot;};<br /> foreach (string person in names)<br /> {<br /> Console.Write (&quot; &quot; + person);<br /> }&lt;/csharp&gt;<br /> <br /> produces&lt;br&gt;<br /> <br /> &lt;pre&gt;<br /> Cheryl Joe Matt Robert<br /> &lt;/pre&gt;<br /> <br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class3/ForEachLoop.cs ForEachLoop.cs - source]<br /> <br /> The for each loop is a key component in polymorphism. Remember the age selector example what if we want to select more than one age. It would be simple to change the dropdownlist into a listbox and turn SelectionMode =&quot;Multiple&quot; so the user can select multiple items but how do check to see if every Item is selected. Is to have each item check itself and use a for each loop.<br /> <br /> ==Generics==<br /> <br /> *List<br /> *Queue<br /> *Stack<br /> *.etc<br /> <br /> ==IN Class==<br /> <br /> Build a c# app that writes the words to 99 bottles of beer on the wall using a loopin statement<br /> [[99 bottles of beer csharp example]]<br /> <br /> ==Try and Catch==<br /> <br /> Try and catch is useful when you are going to do something that may cause a runtime error. These arrroe my occur when<br /> <br /> *Parsing user input<br /> *Converting Datatypes<br /> *Trying to connect to a remote server<br /> *Connecting to a database<br /> <br /> For example consider a program that asks the user what their favorite number is.<br /> <br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> <br /> namespace FavoriteNumber<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> int intFavNumber;<br /> string strFavNumber;<br /> <br /> Console.Write(&quot;What is you favorite number?&quot;);<br /> strFavNumber = Console.ReadLine();<br /> <br /> intFavNumber = Int16.Parse(strFavNumber);<br /> <br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> if you type 'monkey' for your favorite number the program crashes with the folling message<br /> &lt;pre&gt;<br /> <br /> Unhandled Exception: System.FormatException: Input string was not in a correct format.<br /> at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer&amp; number, NumberFormatInfo info, Boolea<br /> n parseDecimal)<br /> at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)<br /> at System.Int16.Parse(String s, NumberStyles style, NumberFormatInfo info)<br /> at FavoriteNumber.Program.Main(String[] args)<br /> &lt;/pre&gt;<br /> <br /> This program can be fixed be using a try and catch<br /> <br /> &lt;csharp&gt;try<br /> {<br /> //some crazy code that may cause errors<br /> }<br /> catch (Exception e)<br /> {<br /> string FstrError = e.ToString();<br /> }&lt;/csharp&gt;<br /> <br /> <br /> <br /> Console Example<br /> http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class3/try.cs<br /> <br /> &lt;csharp&gt;using System;<br /> namespace HelloClass<br /> {<br /> class HelloWorld<br /> {<br /> public static void Main()<br /> {<br /> object o2 = null;<br /> try<br /> {<br /> int i2 = (int) o2; // Error<br /> }<br /> catch (Exception e)<br /> {<br /> //put Exceptioninto string strError<br /> string strError = e.ToString();<br /> //write error to label lblOutput<br /> Console.WriteLine(strError);<br /> }<br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> &lt;pre&gt;<br /> C:\User\csharp&gt;csc try.cs<br /> Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4<br /> for Microsoft (R) .NET Framework version 1.1.4322<br /> Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.<br /> <br /> <br /> C:\User\csharp&gt;try.exe<br /> System.NullReferenceException: Object reference not set to an instance of an obj<br /> ect.<br /> at HelloClass.HelloWorld.Main()<br /> <br /> C:\User\csharp&gt;<br /> &lt;/pre&gt;<br /> /infod/jeff/classSource/class2/try.cs - source<br /> <br /> {{Csharp string functions}}<br /> <br /> ==Functions/Methods==<br /> <br /> Function help with code reuse. If your going to use it more than once make it into a funtions.<br /> syntax simple<br /> <br /> [access-modifier] return type indentifier ( [parateters] )<br /> {<br /> //some code<br /> }<br /> <br /> access-modifiers&lt;br&gt;<br /> public&lt;br&gt;<br /> private&lt;br&gt;<br /> protected&lt;br&gt;<br /> internal&lt;br&gt;<br /> protected internal&lt;br&gt;<br /> more on these next week. <br /> <br /> Defining<br /> <br /> &lt;csharp&gt;string Hello ()<br /> {<br /> return &quot;Hello &quot;;<br /> }<br /> <br /> string HelloToName (string Name)<br /> {<br /> return &quot;Hello &quot; + Name;<br /> }&lt;/csharp&gt;<br /> <br /> Calling a finction in c#<br /> <br /> &lt;csharp&gt;string firstHello, jeffHello; //declare some strings<br /> firstHello = Hello(); //call the function Hello<br /> jeffHello = HelloToName(&quot;Jeff&quot;); //call the function HelloToName<br /> &lt;/csharp&gt;<br /> <br /> Console Example<br /> /infod/jeff/classSource/class3/function.cs - source<br /> &lt;pre&gt;<br /> C:\User\csharp&gt;csc function.cs<br /> Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4<br /> for Microsoft (R) .NET Framework version 1.1.4322<br /> Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.<br /> <br /> <br /> C:\User\csharp&gt;function.cs<br /> <br /> C:\User\csharp&gt;function.exe<br /> Hello World!<br /> Hello<br /> Hello Jeff<br /> Hello Marge<br /> <br /> C:\User\csharp&gt;<br /> &lt;/pre&gt;<br /> <br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class3/function.cs function.cs]<br /> <br /> Passing variable into a function/method passes be instance. Variables passed by instance do not actually pass in the original variable rather a copy or new instance of the variable is passed. It you want to pass in the actual variable you need to pass be referance<br /> Examples of passesing by instamce and passing by refecnce...<br /> /infod/jeff/classSource/class3/instanceReference.aspx - Source<br /> <br /> ==Variables==<br /> ===Scope===<br /> <br /> scope defines the life of a variable.<br /> Local Variables<br /> <br /> Variables declared with functions/methods are only around as long as the function/method is running. These variables are known as local varables<br /> ===Global Variables===<br /> <br /> Global variables are variables that are around for the entire length of execution. They are declared a public within the programs base class.&lt;br /&gt;<br /> In c# since everything must be contianed in a class global variables do not really exist.<br /> <br /> ===Block Level Variables===<br /> <br /> Block level variables exitist with the code block.&lt;br /&gt;<br /> A code block is contained by { }.<br /> <br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class3/Scope.cs Scope.cs]&lt;br /&gt;<br /> <br /> <br /> <br /> <br /> ==Additional Reading==<br /> <br /> *http://www.csharp-station.com/Tutorials/Lesson03.aspx<br /> *http://www.csharp-station.com/Tutorials/Lesson04.aspx<br /> <br /> ==Structs==<br /> <br /> Lightweight alternatives to classes. Structs do not support inheritance or destructors. Don't worry if you don't understand structs yet it hard cuz the book teaches them before classes. We will talk more about stucts after we talk about classes<br /> Syntax<br /> <br /> [ attributes] [access-modifiers] struct identifier<br /> [:interface-list {struct members} <br /> <br /> &lt;csharp&gt;struct Dog<br /> {<br /> public string name;<br /> public string weight;<br /> public int age;<br /> }&lt;/csharp&gt;<br /> <br /> ==Enumerators==<br /> <br /> Enumerators are used to set predefined list of named constants.<br /> Syntax<br /> <br /> [ attributes] [modifiers] enum identifier<br /> [:base-type {enumerator-list}; <br /> <br /> &lt;csharp&gt;//An enumerator for ServingSizes at BK<br /> enum ServingSizes : uint<br /> {<br /> Small = 0,<br /> Regular = 1,<br /> Large = 2,<br /> SuperSize = 3<br /> }&lt;/csharp&gt;<br /> <br /> &lt;csharp&gt;//another more useful example<br /> // forced sequence to start <br /> // from 1 instead of 0 (default)<br /> enum Months <br /> {<br /> January = 1, February , March, April ,<br /> May , June , July , August , Sept , Oct , Nov , Dec <br /> }&lt;/csharp&gt;<br /> <br /> Enumerator Example [http://iam.colum.edu/Poop/gbrowser.php?file=/classsource/class2/Enum.cs Enum.cs]<br /> <br /> ==Home work==<br /> <br /> 2. Read Chapter 6,7 in Learning c# <br /> <br /> *Create a console Game of Chance 2 pts<br /> **A coinflipper<br /> **A dice roller<br /> **Guess My Number<br /> <br /> The game should contain some level of randomness.<br /> It should also demonstrate operators and branching statements. It would sure be nice if the game had some level input from the user.<br /> <br /> <br /> Here is an example coin flipper worth 2 pts<br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class3/CoinFilpperSimple.cs CoinFilpperSimple.cs]<br /> <br /> This game flips a whole bunch of coins two and compares the results. If the two coins are the same then you are a winner and it displays true. If they are different then you loose and if displays false.<br /> This program was created to test the old question 'If you flip a coins 99 times and get 99 head what are the odds of the 100th flip turning up heads?' <br /> <br /> It shows some strange properties of randomness.<br /> <br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class3/CoinFilpperFunner.cs CoinFilpperFunner.cs]<br /> <br /> <br /> Quiz 1 next week over weeks 1-3 and Chapter 1-6 in Learning c#<br /> <br /> ==Video==<br /> &lt;html&gt;<br /> &lt;script type='text/javascript' src='http://iam.colum.edu/videotutorials/mediaplayer-5.2/swfobject.js'&gt;&lt;/script&gt; <br /> &lt;div id='mediaspace2'&gt;This text will be replaced&lt;/div&gt; <br /> &lt;script type='text/javascript'&gt;<br /> var so = new SWFObject('http://iam.colum.edu/videotutorials/mediaplayer-5.2/player.swf','mpl','800','600','9');so.addParam('allowfullscreen','true')<br /> ;so.addParam('allowscriptaccess','always');<br /> so.addParam('wmode','opaque');<br /> so.addVariable('file','http://iam.colum.edu/screenz/FA13/OOP_MT/OOP_Class3_MT_Tue/OOP_Class3_MT_Tue.mp4');<br /> so.addVariable('autostart','false');<br /> so.write('mediaspace2');<br /> <br /> &lt;/script&gt;<br /> <br /> &lt;/html&gt;</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class1&diff=21741 OOP Class1 2013-09-16T18:14:37Z <p>Cameron.Cintron: /* Homework */</p> <hr /> <div>==Intro to Lab==<br /> *Create student accounts<br /> *Create Student websites<br /> *Show Source Browser already installed in your oop folder<br /> <br /> ==About Class==<br /> ===Technologies===<br /> * C# 4 '''Programming Language''' [http://en.csharp-online.net/CSharp_Language_Specification ECMA-334 C# Language Specification] [http://msdn.microsoft.com/en-us/vcsharp/aa336809.aspx C# language MSDN] <br /> * .NET Framework 3.5 '''Framework API''' http://www.microsoft.com/downloads/details.aspx?FamilyId=333325FD-AE52-4E35-B531-508D977D32A6&amp;displaylang=en<br /> * NET Framework 4.0 http://www.microsoft.com/downloads/details.aspx?FamilyID=9cfb2d51-5ff4-4491-b0e5-b386f32c0992&amp;displaylang=en<br /> * Mono http://www.mono-project.com/Main_Page<br /> <br /> ==Introduction to Programming languages==<br /> <br /> <br /> '''Compliled vs Interpreted Languages'''&lt;br /&gt;<br /> '''Interpreted Languages'''&lt;br /&gt;<br /> &lt;p&gt;<br /> Interpreted langauges read and parse the source input every time a they are executed. After each line is parsed it is converted to machine language and it is executed. Interperted languages are often referd to as scripting languages and are often good for small projects that need to be deployed quickly.&lt;/p&gt;<br /> Interperated Scripting Languages are often used on the web<br /> <br /> Common Interpreted Languages are [http://www.perl.org Perl],[http://www.php.net PHP], [http://www.python.org/ Python] and [http://www.ruby-lang.org/en/ Ruby]<br /> <br /> '''Compiled Languages'''<br /> &lt;br /&gt;<br /> Compiled languages use a complier to read and parse the input source code and convert it into machine language. The output binary file is then excuted. If the source changes the program needs to be recompiled. Complied prorams often execute faster and add extra layer of security becuase the source is not always readily available and executable. Complied code also tends to take up less memory and system resources.<br /> &lt;br /&gt;<br /> Common Client Side <br /> * javascript - ECMA script http://www.ecma-international.org/publications/standards/stnindex.htm<br /> * VBScript - Microsoft scripting version of Visual Basic http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vtoriVBScript.asp<br /> &lt;br /&gt;<br /> Common Server Side Languages<br /> * PHP (recursive acronym for &quot;PHP: Hypertext Preprocessor&quot;) http://www.php.net/<br /> * ASP Active server Pages uses <br /> **jscript (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsoriJScript.asp) **or **vbscript (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vtoriVBScript.asp)<br /> <br /> &lt;br &gt;<br /> HelloWorld in several common programming languages<br /> [[Hello World Languages]]<br /> <br /> ===Why .NET?=== <br /> <br /> *Discussion<br /> <br /> .Net is a platform from Microsoft. It consists of several components. The base of the new platform is the [http://en.wikipedia.org/wiki/Microsoft_.NET] .NET framework. The .NET framework sits on top of the windows(or other operating systems like [http://www.mono-project.com/Main_Page mono]). The .net framework consists of the Common Language Runtime(CLR) and the [http://msdn.microsoft.com/en-us/library/ms229335.aspx Framework Class Library(FCL)]. <br /> <br /> <br /> The CLR is a platform for compiling, debugging and executing .NET applications. Like java the CLR a virtual machine that can better control runtime security, memory management, and threading.<br /> <br /> Here are some examples of the classes available in the .NET framework <br /> <br /> *System Contains fundamental classes and base classes that define commonly used value and reference data types, events and event handlers, interfaces, attributes, and processing exceptions.<br /> *System.Data Consists mostly of the classes that constitute the ADO.NET architecture. The ADO.NET architecture enables you to build components that efficiently manage data from multiple data sources. In a disconnected scenario (such as the Internet), ADO.NET provides the tools to request, update, and reconcile data in multiple tier systems. The ADO.NET architecture is also implemented in client applications, such as Windows Forms, or HTML pages created by ASP.NET.<br /> *System.Data.Common Contains classes shared by the .NET Framework data providers. A .NET Framework data provider describes a collection of classes used to access a data source, such as a database, in the managed space.<br /> *System.Data.SqlClient Encapsulates the .NET Framework Data Provider for SQL Server. The .NET Framework Data Provider for SQL Server describes a collection of classes used to access a SQL Server database in the managed space.<br /> *System.Drawing Provides access to GDI+ basic graphics functionality. More advanced functionality is provided in the<br /> *System.Drawing.Drawing2D Provides advanced 2-dimensional and vector graphics functionality. This namespace includes the gradient brushes, the Matrix class (used to define geometric transforms), and the GraphicsPath class.<br /> *System.Drawing.Imaging Provides advanced GDI+ imaging functionality. Basic graphics functionality is provided by the System.Drawing namespace.<br /> *System.Web Supplies classes and interfaces that enable browser-server communication.<br /> *System.Web.UI Provides classes and interfaces that allow you to create controls and pages that will appear in your Web applications as user interface on a Web page.<br /> System.Web.UI.HtmlControls Consists of a collection of classes that allow you to create HTML server controls on a Web Forms page. HTML server controls run on the server and map directly to standard HTML tags supported by most browsers. This allows you to programmatically control the HTML elements on a Web Forms page.<br /> *System.Web.UI.WebControls Contains classes that allow you to create Web server controls on a Web page. Web server controls run on the server and include form controls such as buttons and text boxes. They also include special purpose controls such as a calendar. Because Web server controls run on the server, you can programmatically control these elements. Web server controls are more abstract than HTML server controls. Their object model does not necessarily reflect HTML syntax.<br /> *System.Windows.Forms Contains classes that support design-time configuration and behavior for Windows Forms components.<br /> Full List with descriptions http://msdn.microsoft.com/en-us/library/ms229335.aspx<br /> <br /> Unlike Java the Microsoft CLR supports multiple languages.<br /> <br /> Sun and Microsoft have different programing philosophies.<br /> Java write once (in java) run anywhere.<br /> CLR write in any CLR language and run on .NET<br /> The CLR from Microsoft supports several languages.<br /> <br /> * C# - java like language pronounced C Sharp (the language we will use for this course)<br /> * VB.NET - Visual Basic .NET<br /> * JScript<br /> * J# - Microsoft's Java-language<br /> * third party languages (cobol,eiffel,pascal,perl) [http://msdn.microsoft.com/vstudio/partners/language/default.asp Programming Language Partners] <br /> <br /> The CLR compiles the .NET languages into MS Intermediate Language (MSIL) which is similar to java's object code. It is an intermediary step between programming language and machine code. The MSIL allows .NET to support multiple programming languages. MSIL code is further compiled by the CLR at run time into machine code. This is known as JIT compilation or Just In Time.<br /> <br /> ===.NET Applications===<br /> <br /> * Console Applications<br /> * Windows Forms http://windowsclient.net/getstarted/<br /> * Windows Presentation Forms http://windowsclient.net/getstarted/ http://windowsclient.net/learn/videos_wpf.aspx<br /> * Web Forms http://asp.net/get-started/<br /> * Web Services<br /> * XNA http://creators.xna.com/en-US/quickstart_main<br /> <br /> *[http://msdn.microsoft.com/en-us/library/aa288463(VS.71).aspx Hello World Tutorial MSDN]<br /> <br /> Hello world in C# for console really simple<br /> &lt;csharp&gt;using System;<br /> namespace HelloClass<br /> {<br /> class HelloWorld<br /> {<br /> //All Console Apps start with Main Method<br /> public static void Main()<br /> {<br /> Console.WriteLine(&quot;Hello World!&quot;);<br /> <br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> ==Hello Console==<br /> <br /> &lt;csharp&gt;using System;<br /> using System.Collections.Generic;<br /> using System.Linq;<br /> using System.Text;<br /> <br /> namespace HelloWorldConsole<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Hello World!&quot;); //Write Hello World! to the console standard out<br /> }<br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> <br /> http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class1/HelloWorldConsole/HelloWorldConsole/Program.cs<br /> <br /> MSIL<br /> &lt;csharp&gt;.method public hidebysig static void Main() cil managed<br /> {<br /> .entrypoint<br /> // Code size 11 (0xb)<br /> .maxstack 1<br /> IL_0000: ldstr &quot;Hello World!&quot;<br /> IL_0005: call void [mscorlib]System.Console::WriteLine(string)<br /> IL_000a: ret<br /> } // end of method HelloWorldConsole::Main<br /> &lt;/csharp&gt;<br /> Fully Disassembled hello.cs<br /> <br /> ==Hello WinForms==<br /> form1.cs<br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.ComponentModel;<br /> using System.Data;<br /> using System.Drawing;<br /> using System.Linq;<br /> using System.Text;<br /> using System.Windows.Forms;<br /> <br /> namespace HelloWorldWindowsForms<br /> {<br /> public partial class Form1 : Form<br /> {<br /> public Form1()<br /> {<br /> InitializeComponent();<br /> }<br /> <br /> private void Form1_Load(object sender, EventArgs e)<br /> {<br /> this.Text = &quot;Hello World App&quot;; //Change the title of the form<br /> //yeah i know i could have done it in the designer<br /> <br /> label1.Text = &quot;Hello World!&quot;; //Say Hello in a Label<br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class1/HelloWorldWindowsForms/HelloWorldWindowsForms/Form1.cs<br /> <br /> ==Helloworld! WPF==<br /> <br /> Window1.xaml.cs<br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Linq;<br /> using System.Text;<br /> using System.Windows;<br /> using System.Windows.Controls;<br /> using System.Windows.Data;<br /> using System.Windows.Documents;<br /> using System.Windows.Input;<br /> using System.Windows.Media;<br /> using System.Windows.Media.Imaging;<br /> using System.Windows.Navigation;<br /> using System.Windows.Shapes;<br /> <br /> namespace HelloWorldWpfApplication<br /> {<br /> /// &lt;summary&gt;<br /> /// Interaction logic for Window1.xaml<br /> /// &lt;/summary&gt;<br /> public partial class Window1 : Window<br /> {<br /> public Window1()<br /> {<br /> InitializeComponent();<br /> }<br /> <br /> private void Canvas_Loaded(object sender, RoutedEventArgs e)<br /> {<br /> this.Title = &quot;Hello WPF app&quot;;<br /> tbHello.Text = &quot;Hello World!&quot;; //Say hello to wpd TexBloc<br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> window1.xaml<br /> &lt;xml&gt;<br /> &lt;Window x:Class=&quot;HelloWorldWpfApplication.Window1&quot;<br /> xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;<br /> xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;<br /> Title=&quot;Window1&quot; Height=&quot;300&quot; Width=&quot;300&quot;&gt;<br /> &lt;Grid&gt;<br /> &lt;Canvas Loaded=&quot;Canvas_Loaded&quot;&gt;<br /> &lt;TextBlock x:Name=&quot;tbHello&quot; Canvas.Left=&quot;100&quot; Canvas.Top=&quot;100&quot;&gt;&lt;/TextBlock&gt;<br /> &lt;/Canvas&gt;<br /> <br /> &lt;/Grid&gt;<br /> &lt;/Window&gt;<br /> <br /> &lt;/xml&gt;<br /> <br /> ==Other Links==<br /> [http://www.ecma-international.org/publications/standards/Ecma-334.htm ECMA C# and Common Language Infrastructure Standards]&lt;br&gt;<br /> [http://www.mono-project.com/Main_Page Mono] - Ximian Linux .NET Copy&lt;br&gt;<br /> [http://www.gotdotnet.com/ GotDotNet] - Microsoft Site to bridge the gap between .NET team and .NET developers/students&lt;br&gt;<br /> <br /> <br /> <br /> ==Homework==<br /> <br /> #get .Net Framework 4.0 [http://www.microsoft.com/downloads/details.aspx?FamilyID=333325fd-ae52-4e35-b531-508d977d32a6&amp;displaylang=en Microsoft .NET Framework 3.5] and .Net SDK [http://msdn.microsoft.com/en-us/netframework/default.aspx .NET SKD] or Mono [http://www.go-mono.com/mono-downloads/download.html Mono Downloads] or VS2010 (handed out in class) and install it<br /> #write and compile [[Helloworld in csharp]] as a c# console application '''bonus''' make hello world in something besides the console and make it interactive<br /> #Read Learning c# Chapters 1-5 pg 0-46<br /> <br /> *[http://msdn.microsoft.com/en-us/library/aa288463(VS.71).aspx Hello World Tutorial MSDN]<br /> <br /> [[OOP Class1]<br /> <br /> [[Category:IAM Classes]][[Category:Object Oriented Programming]]<br /> <br /> ===Video===<br /> <br /> &lt;html&gt;<br /> &lt;script type='text/javascript' src='http://iam.colum.edu/videotutorials/mediaplayer-5.2/swfobject.js'&gt;&lt;/script&gt; <br /> &lt;div id='mediaspace2'&gt;This text will be replaced&lt;/div&gt; <br /> &lt;script type='text/javascript'&gt;<br /> var so = new SWFObject('http://iam.colum.edu/videotutorials/mediaplayer-5.2/player.swf','mpl','800','600','9');so.addParam('allowfullscreen','true')<br /> ;so.addParam('allowscriptaccess','always');<br /> so.addParam('wmode','opaque');<br /> so.addVariable('file','http://iam.colum.edu/screenz/FA13/OOP_Class1_JM/OOP_Class1_JM.mp4');<br /> so.addVariable('autostart','false');<br /> so.write('mediaspace2');<br /> <br /> &lt;/script&gt;<br /> <br /> &lt;/html&gt;</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class1&diff=21740 OOP Class1 2013-09-16T18:14:18Z <p>Cameron.Cintron: /* Video */</p> <hr /> <div>==Intro to Lab==<br /> *Create student accounts<br /> *Create Student websites<br /> *Show Source Browser already installed in your oop folder<br /> <br /> ==About Class==<br /> ===Technologies===<br /> * C# 4 '''Programming Language''' [http://en.csharp-online.net/CSharp_Language_Specification ECMA-334 C# Language Specification] [http://msdn.microsoft.com/en-us/vcsharp/aa336809.aspx C# language MSDN] <br /> * .NET Framework 3.5 '''Framework API''' http://www.microsoft.com/downloads/details.aspx?FamilyId=333325FD-AE52-4E35-B531-508D977D32A6&amp;displaylang=en<br /> * NET Framework 4.0 http://www.microsoft.com/downloads/details.aspx?FamilyID=9cfb2d51-5ff4-4491-b0e5-b386f32c0992&amp;displaylang=en<br /> * Mono http://www.mono-project.com/Main_Page<br /> <br /> ==Introduction to Programming languages==<br /> <br /> <br /> '''Compliled vs Interpreted Languages'''&lt;br /&gt;<br /> '''Interpreted Languages'''&lt;br /&gt;<br /> &lt;p&gt;<br /> Interpreted langauges read and parse the source input every time a they are executed. After each line is parsed it is converted to machine language and it is executed. Interperted languages are often referd to as scripting languages and are often good for small projects that need to be deployed quickly.&lt;/p&gt;<br /> Interperated Scripting Languages are often used on the web<br /> <br /> Common Interpreted Languages are [http://www.perl.org Perl],[http://www.php.net PHP], [http://www.python.org/ Python] and [http://www.ruby-lang.org/en/ Ruby]<br /> <br /> '''Compiled Languages'''<br /> &lt;br /&gt;<br /> Compiled languages use a complier to read and parse the input source code and convert it into machine language. The output binary file is then excuted. If the source changes the program needs to be recompiled. Complied prorams often execute faster and add extra layer of security becuase the source is not always readily available and executable. Complied code also tends to take up less memory and system resources.<br /> &lt;br /&gt;<br /> Common Client Side <br /> * javascript - ECMA script http://www.ecma-international.org/publications/standards/stnindex.htm<br /> * VBScript - Microsoft scripting version of Visual Basic http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vtoriVBScript.asp<br /> &lt;br /&gt;<br /> Common Server Side Languages<br /> * PHP (recursive acronym for &quot;PHP: Hypertext Preprocessor&quot;) http://www.php.net/<br /> * ASP Active server Pages uses <br /> **jscript (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsoriJScript.asp) **or **vbscript (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vtoriVBScript.asp)<br /> <br /> &lt;br &gt;<br /> HelloWorld in several common programming languages<br /> [[Hello World Languages]]<br /> <br /> ===Why .NET?=== <br /> <br /> *Discussion<br /> <br /> .Net is a platform from Microsoft. It consists of several components. The base of the new platform is the [http://en.wikipedia.org/wiki/Microsoft_.NET] .NET framework. The .NET framework sits on top of the windows(or other operating systems like [http://www.mono-project.com/Main_Page mono]). The .net framework consists of the Common Language Runtime(CLR) and the [http://msdn.microsoft.com/en-us/library/ms229335.aspx Framework Class Library(FCL)]. <br /> <br /> <br /> The CLR is a platform for compiling, debugging and executing .NET applications. Like java the CLR a virtual machine that can better control runtime security, memory management, and threading.<br /> <br /> Here are some examples of the classes available in the .NET framework <br /> <br /> *System Contains fundamental classes and base classes that define commonly used value and reference data types, events and event handlers, interfaces, attributes, and processing exceptions.<br /> *System.Data Consists mostly of the classes that constitute the ADO.NET architecture. The ADO.NET architecture enables you to build components that efficiently manage data from multiple data sources. In a disconnected scenario (such as the Internet), ADO.NET provides the tools to request, update, and reconcile data in multiple tier systems. The ADO.NET architecture is also implemented in client applications, such as Windows Forms, or HTML pages created by ASP.NET.<br /> *System.Data.Common Contains classes shared by the .NET Framework data providers. A .NET Framework data provider describes a collection of classes used to access a data source, such as a database, in the managed space.<br /> *System.Data.SqlClient Encapsulates the .NET Framework Data Provider for SQL Server. The .NET Framework Data Provider for SQL Server describes a collection of classes used to access a SQL Server database in the managed space.<br /> *System.Drawing Provides access to GDI+ basic graphics functionality. More advanced functionality is provided in the<br /> *System.Drawing.Drawing2D Provides advanced 2-dimensional and vector graphics functionality. This namespace includes the gradient brushes, the Matrix class (used to define geometric transforms), and the GraphicsPath class.<br /> *System.Drawing.Imaging Provides advanced GDI+ imaging functionality. Basic graphics functionality is provided by the System.Drawing namespace.<br /> *System.Web Supplies classes and interfaces that enable browser-server communication.<br /> *System.Web.UI Provides classes and interfaces that allow you to create controls and pages that will appear in your Web applications as user interface on a Web page.<br /> System.Web.UI.HtmlControls Consists of a collection of classes that allow you to create HTML server controls on a Web Forms page. HTML server controls run on the server and map directly to standard HTML tags supported by most browsers. This allows you to programmatically control the HTML elements on a Web Forms page.<br /> *System.Web.UI.WebControls Contains classes that allow you to create Web server controls on a Web page. Web server controls run on the server and include form controls such as buttons and text boxes. They also include special purpose controls such as a calendar. Because Web server controls run on the server, you can programmatically control these elements. Web server controls are more abstract than HTML server controls. Their object model does not necessarily reflect HTML syntax.<br /> *System.Windows.Forms Contains classes that support design-time configuration and behavior for Windows Forms components.<br /> Full List with descriptions http://msdn.microsoft.com/en-us/library/ms229335.aspx<br /> <br /> Unlike Java the Microsoft CLR supports multiple languages.<br /> <br /> Sun and Microsoft have different programing philosophies.<br /> Java write once (in java) run anywhere.<br /> CLR write in any CLR language and run on .NET<br /> The CLR from Microsoft supports several languages.<br /> <br /> * C# - java like language pronounced C Sharp (the language we will use for this course)<br /> * VB.NET - Visual Basic .NET<br /> * JScript<br /> * J# - Microsoft's Java-language<br /> * third party languages (cobol,eiffel,pascal,perl) [http://msdn.microsoft.com/vstudio/partners/language/default.asp Programming Language Partners] <br /> <br /> The CLR compiles the .NET languages into MS Intermediate Language (MSIL) which is similar to java's object code. It is an intermediary step between programming language and machine code. The MSIL allows .NET to support multiple programming languages. MSIL code is further compiled by the CLR at run time into machine code. This is known as JIT compilation or Just In Time.<br /> <br /> ===.NET Applications===<br /> <br /> * Console Applications<br /> * Windows Forms http://windowsclient.net/getstarted/<br /> * Windows Presentation Forms http://windowsclient.net/getstarted/ http://windowsclient.net/learn/videos_wpf.aspx<br /> * Web Forms http://asp.net/get-started/<br /> * Web Services<br /> * XNA http://creators.xna.com/en-US/quickstart_main<br /> <br /> *[http://msdn.microsoft.com/en-us/library/aa288463(VS.71).aspx Hello World Tutorial MSDN]<br /> <br /> Hello world in C# for console really simple<br /> &lt;csharp&gt;using System;<br /> namespace HelloClass<br /> {<br /> class HelloWorld<br /> {<br /> //All Console Apps start with Main Method<br /> public static void Main()<br /> {<br /> Console.WriteLine(&quot;Hello World!&quot;);<br /> <br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> ==Hello Console==<br /> <br /> &lt;csharp&gt;using System;<br /> using System.Collections.Generic;<br /> using System.Linq;<br /> using System.Text;<br /> <br /> namespace HelloWorldConsole<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Hello World!&quot;); //Write Hello World! to the console standard out<br /> }<br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> <br /> http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class1/HelloWorldConsole/HelloWorldConsole/Program.cs<br /> <br /> MSIL<br /> &lt;csharp&gt;.method public hidebysig static void Main() cil managed<br /> {<br /> .entrypoint<br /> // Code size 11 (0xb)<br /> .maxstack 1<br /> IL_0000: ldstr &quot;Hello World!&quot;<br /> IL_0005: call void [mscorlib]System.Console::WriteLine(string)<br /> IL_000a: ret<br /> } // end of method HelloWorldConsole::Main<br /> &lt;/csharp&gt;<br /> Fully Disassembled hello.cs<br /> <br /> ==Hello WinForms==<br /> form1.cs<br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.ComponentModel;<br /> using System.Data;<br /> using System.Drawing;<br /> using System.Linq;<br /> using System.Text;<br /> using System.Windows.Forms;<br /> <br /> namespace HelloWorldWindowsForms<br /> {<br /> public partial class Form1 : Form<br /> {<br /> public Form1()<br /> {<br /> InitializeComponent();<br /> }<br /> <br /> private void Form1_Load(object sender, EventArgs e)<br /> {<br /> this.Text = &quot;Hello World App&quot;; //Change the title of the form<br /> //yeah i know i could have done it in the designer<br /> <br /> label1.Text = &quot;Hello World!&quot;; //Say Hello in a Label<br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class1/HelloWorldWindowsForms/HelloWorldWindowsForms/Form1.cs<br /> <br /> ==Helloworld! WPF==<br /> <br /> Window1.xaml.cs<br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Linq;<br /> using System.Text;<br /> using System.Windows;<br /> using System.Windows.Controls;<br /> using System.Windows.Data;<br /> using System.Windows.Documents;<br /> using System.Windows.Input;<br /> using System.Windows.Media;<br /> using System.Windows.Media.Imaging;<br /> using System.Windows.Navigation;<br /> using System.Windows.Shapes;<br /> <br /> namespace HelloWorldWpfApplication<br /> {<br /> /// &lt;summary&gt;<br /> /// Interaction logic for Window1.xaml<br /> /// &lt;/summary&gt;<br /> public partial class Window1 : Window<br /> {<br /> public Window1()<br /> {<br /> InitializeComponent();<br /> }<br /> <br /> private void Canvas_Loaded(object sender, RoutedEventArgs e)<br /> {<br /> this.Title = &quot;Hello WPF app&quot;;<br /> tbHello.Text = &quot;Hello World!&quot;; //Say hello to wpd TexBloc<br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> window1.xaml<br /> &lt;xml&gt;<br /> &lt;Window x:Class=&quot;HelloWorldWpfApplication.Window1&quot;<br /> xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;<br /> xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;<br /> Title=&quot;Window1&quot; Height=&quot;300&quot; Width=&quot;300&quot;&gt;<br /> &lt;Grid&gt;<br /> &lt;Canvas Loaded=&quot;Canvas_Loaded&quot;&gt;<br /> &lt;TextBlock x:Name=&quot;tbHello&quot; Canvas.Left=&quot;100&quot; Canvas.Top=&quot;100&quot;&gt;&lt;/TextBlock&gt;<br /> &lt;/Canvas&gt;<br /> <br /> &lt;/Grid&gt;<br /> &lt;/Window&gt;<br /> <br /> &lt;/xml&gt;<br /> <br /> ==Other Links==<br /> [http://www.ecma-international.org/publications/standards/Ecma-334.htm ECMA C# and Common Language Infrastructure Standards]&lt;br&gt;<br /> [http://www.mono-project.com/Main_Page Mono] - Ximian Linux .NET Copy&lt;br&gt;<br /> [http://www.gotdotnet.com/ GotDotNet] - Microsoft Site to bridge the gap between .NET team and .NET developers/students&lt;br&gt;<br /> <br /> <br /> <br /> ==Homework==<br /> <br /> #get .Net Framework 4.0 [http://www.microsoft.com/downloads/details.aspx?FamilyID=333325fd-ae52-4e35-b531-508d977d32a6&amp;displaylang=en Microsoft .NET Framework 3.5] and .Net SDK [http://msdn.microsoft.com/en-us/netframework/default.aspx .NET SKD] or Mono [http://www.go-mono.com/mono-downloads/download.html Mono Downloads] or VS2010 (handed out in class) and install it<br /> #write and compile [[Helloworld in csharp]] as a c# console application '''bonus''' make hello world in something besides the console and make it interactive<br /> #Read Learning c# Chapters 1-5 pg 0-46<br /> <br /> *[http://msdn.microsoft.com/en-us/library/aa288463(VS.71).aspx Hello World Tutorial MSDN]<br /> <br /> [[OOP Class1]<br /> <br /> [[Category:IAM Classes]][[Category:Object Oriented Programming]]</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class1&diff=21739 OOP Class1 2013-09-16T18:14:01Z <p>Cameron.Cintron: /* Introduction to Programming languages */</p> <hr /> <div>==Intro to Lab==<br /> *Create student accounts<br /> *Create Student websites<br /> *Show Source Browser already installed in your oop folder<br /> <br /> ==About Class==<br /> ===Technologies===<br /> * C# 4 '''Programming Language''' [http://en.csharp-online.net/CSharp_Language_Specification ECMA-334 C# Language Specification] [http://msdn.microsoft.com/en-us/vcsharp/aa336809.aspx C# language MSDN] <br /> * .NET Framework 3.5 '''Framework API''' http://www.microsoft.com/downloads/details.aspx?FamilyId=333325FD-AE52-4E35-B531-508D977D32A6&amp;displaylang=en<br /> * NET Framework 4.0 http://www.microsoft.com/downloads/details.aspx?FamilyID=9cfb2d51-5ff4-4491-b0e5-b386f32c0992&amp;displaylang=en<br /> * Mono http://www.mono-project.com/Main_Page<br /> <br /> ==Introduction to Programming languages==<br /> <br /> <br /> '''Compliled vs Interpreted Languages'''&lt;br /&gt;<br /> '''Interpreted Languages'''&lt;br /&gt;<br /> &lt;p&gt;<br /> Interpreted langauges read and parse the source input every time a they are executed. After each line is parsed it is converted to machine language and it is executed. Interperted languages are often referd to as scripting languages and are often good for small projects that need to be deployed quickly.&lt;/p&gt;<br /> Interperated Scripting Languages are often used on the web<br /> <br /> Common Interpreted Languages are [http://www.perl.org Perl],[http://www.php.net PHP], [http://www.python.org/ Python] and [http://www.ruby-lang.org/en/ Ruby]<br /> <br /> '''Compiled Languages'''<br /> &lt;br /&gt;<br /> Compiled languages use a complier to read and parse the input source code and convert it into machine language. The output binary file is then excuted. If the source changes the program needs to be recompiled. Complied prorams often execute faster and add extra layer of security becuase the source is not always readily available and executable. Complied code also tends to take up less memory and system resources.<br /> &lt;br /&gt;<br /> Common Client Side <br /> * javascript - ECMA script http://www.ecma-international.org/publications/standards/stnindex.htm<br /> * VBScript - Microsoft scripting version of Visual Basic http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vtoriVBScript.asp<br /> &lt;br /&gt;<br /> Common Server Side Languages<br /> * PHP (recursive acronym for &quot;PHP: Hypertext Preprocessor&quot;) http://www.php.net/<br /> * ASP Active server Pages uses <br /> **jscript (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsoriJScript.asp) **or **vbscript (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vtoriVBScript.asp)<br /> <br /> &lt;br &gt;<br /> HelloWorld in several common programming languages<br /> [[Hello World Languages]]<br /> <br /> ===Why .NET?=== <br /> <br /> *Discussion<br /> <br /> .Net is a platform from Microsoft. It consists of several components. The base of the new platform is the [http://en.wikipedia.org/wiki/Microsoft_.NET] .NET framework. The .NET framework sits on top of the windows(or other operating systems like [http://www.mono-project.com/Main_Page mono]). The .net framework consists of the Common Language Runtime(CLR) and the [http://msdn.microsoft.com/en-us/library/ms229335.aspx Framework Class Library(FCL)]. <br /> <br /> <br /> The CLR is a platform for compiling, debugging and executing .NET applications. Like java the CLR a virtual machine that can better control runtime security, memory management, and threading.<br /> <br /> Here are some examples of the classes available in the .NET framework <br /> <br /> *System Contains fundamental classes and base classes that define commonly used value and reference data types, events and event handlers, interfaces, attributes, and processing exceptions.<br /> *System.Data Consists mostly of the classes that constitute the ADO.NET architecture. The ADO.NET architecture enables you to build components that efficiently manage data from multiple data sources. In a disconnected scenario (such as the Internet), ADO.NET provides the tools to request, update, and reconcile data in multiple tier systems. The ADO.NET architecture is also implemented in client applications, such as Windows Forms, or HTML pages created by ASP.NET.<br /> *System.Data.Common Contains classes shared by the .NET Framework data providers. A .NET Framework data provider describes a collection of classes used to access a data source, such as a database, in the managed space.<br /> *System.Data.SqlClient Encapsulates the .NET Framework Data Provider for SQL Server. The .NET Framework Data Provider for SQL Server describes a collection of classes used to access a SQL Server database in the managed space.<br /> *System.Drawing Provides access to GDI+ basic graphics functionality. More advanced functionality is provided in the<br /> *System.Drawing.Drawing2D Provides advanced 2-dimensional and vector graphics functionality. This namespace includes the gradient brushes, the Matrix class (used to define geometric transforms), and the GraphicsPath class.<br /> *System.Drawing.Imaging Provides advanced GDI+ imaging functionality. Basic graphics functionality is provided by the System.Drawing namespace.<br /> *System.Web Supplies classes and interfaces that enable browser-server communication.<br /> *System.Web.UI Provides classes and interfaces that allow you to create controls and pages that will appear in your Web applications as user interface on a Web page.<br /> System.Web.UI.HtmlControls Consists of a collection of classes that allow you to create HTML server controls on a Web Forms page. HTML server controls run on the server and map directly to standard HTML tags supported by most browsers. This allows you to programmatically control the HTML elements on a Web Forms page.<br /> *System.Web.UI.WebControls Contains classes that allow you to create Web server controls on a Web page. Web server controls run on the server and include form controls such as buttons and text boxes. They also include special purpose controls such as a calendar. Because Web server controls run on the server, you can programmatically control these elements. Web server controls are more abstract than HTML server controls. Their object model does not necessarily reflect HTML syntax.<br /> *System.Windows.Forms Contains classes that support design-time configuration and behavior for Windows Forms components.<br /> Full List with descriptions http://msdn.microsoft.com/en-us/library/ms229335.aspx<br /> <br /> Unlike Java the Microsoft CLR supports multiple languages.<br /> <br /> Sun and Microsoft have different programing philosophies.<br /> Java write once (in java) run anywhere.<br /> CLR write in any CLR language and run on .NET<br /> The CLR from Microsoft supports several languages.<br /> <br /> * C# - java like language pronounced C Sharp (the language we will use for this course)<br /> * VB.NET - Visual Basic .NET<br /> * JScript<br /> * J# - Microsoft's Java-language<br /> * third party languages (cobol,eiffel,pascal,perl) [http://msdn.microsoft.com/vstudio/partners/language/default.asp Programming Language Partners] <br /> <br /> The CLR compiles the .NET languages into MS Intermediate Language (MSIL) which is similar to java's object code. It is an intermediary step between programming language and machine code. The MSIL allows .NET to support multiple programming languages. MSIL code is further compiled by the CLR at run time into machine code. This is known as JIT compilation or Just In Time.<br /> <br /> ===.NET Applications===<br /> <br /> * Console Applications<br /> * Windows Forms http://windowsclient.net/getstarted/<br /> * Windows Presentation Forms http://windowsclient.net/getstarted/ http://windowsclient.net/learn/videos_wpf.aspx<br /> * Web Forms http://asp.net/get-started/<br /> * Web Services<br /> * XNA http://creators.xna.com/en-US/quickstart_main<br /> <br /> *[http://msdn.microsoft.com/en-us/library/aa288463(VS.71).aspx Hello World Tutorial MSDN]<br /> <br /> Hello world in C# for console really simple<br /> &lt;csharp&gt;using System;<br /> namespace HelloClass<br /> {<br /> class HelloWorld<br /> {<br /> //All Console Apps start with Main Method<br /> public static void Main()<br /> {<br /> Console.WriteLine(&quot;Hello World!&quot;);<br /> <br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> ===Video===<br /> <br /> &lt;html&gt;<br /> &lt;script type='text/javascript' src='http://iam.colum.edu/videotutorials/mediaplayer-5.2/swfobject.js'&gt;&lt;/script&gt; <br /> &lt;div id='mediaspace2'&gt;This text will be replaced&lt;/div&gt; <br /> &lt;script type='text/javascript'&gt;<br /> var so = new SWFObject('http://iam.colum.edu/videotutorials/mediaplayer-5.2/player.swf','mpl','800','600','9');so.addParam('allowfullscreen','true')<br /> ;so.addParam('allowscriptaccess','always');<br /> so.addParam('wmode','opaque');<br /> so.addVariable('file','http://iam.colum.edu/screenz/FA13/OOP_Class1_JM/OOP_Class1_JM.mp4');<br /> so.addVariable('autostart','false');<br /> so.write('mediaspace2');<br /> <br /> &lt;/script&gt;<br /> <br /> &lt;/html&gt;<br /> <br /> ==Hello Console==<br /> <br /> &lt;csharp&gt;using System;<br /> using System.Collections.Generic;<br /> using System.Linq;<br /> using System.Text;<br /> <br /> namespace HelloWorldConsole<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Hello World!&quot;); //Write Hello World! to the console standard out<br /> }<br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> <br /> http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class1/HelloWorldConsole/HelloWorldConsole/Program.cs<br /> <br /> MSIL<br /> &lt;csharp&gt;.method public hidebysig static void Main() cil managed<br /> {<br /> .entrypoint<br /> // Code size 11 (0xb)<br /> .maxstack 1<br /> IL_0000: ldstr &quot;Hello World!&quot;<br /> IL_0005: call void [mscorlib]System.Console::WriteLine(string)<br /> IL_000a: ret<br /> } // end of method HelloWorldConsole::Main<br /> &lt;/csharp&gt;<br /> Fully Disassembled hello.cs<br /> <br /> ==Hello WinForms==<br /> form1.cs<br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.ComponentModel;<br /> using System.Data;<br /> using System.Drawing;<br /> using System.Linq;<br /> using System.Text;<br /> using System.Windows.Forms;<br /> <br /> namespace HelloWorldWindowsForms<br /> {<br /> public partial class Form1 : Form<br /> {<br /> public Form1()<br /> {<br /> InitializeComponent();<br /> }<br /> <br /> private void Form1_Load(object sender, EventArgs e)<br /> {<br /> this.Text = &quot;Hello World App&quot;; //Change the title of the form<br /> //yeah i know i could have done it in the designer<br /> <br /> label1.Text = &quot;Hello World!&quot;; //Say Hello in a Label<br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class1/HelloWorldWindowsForms/HelloWorldWindowsForms/Form1.cs<br /> <br /> ==Helloworld! WPF==<br /> <br /> Window1.xaml.cs<br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Linq;<br /> using System.Text;<br /> using System.Windows;<br /> using System.Windows.Controls;<br /> using System.Windows.Data;<br /> using System.Windows.Documents;<br /> using System.Windows.Input;<br /> using System.Windows.Media;<br /> using System.Windows.Media.Imaging;<br /> using System.Windows.Navigation;<br /> using System.Windows.Shapes;<br /> <br /> namespace HelloWorldWpfApplication<br /> {<br /> /// &lt;summary&gt;<br /> /// Interaction logic for Window1.xaml<br /> /// &lt;/summary&gt;<br /> public partial class Window1 : Window<br /> {<br /> public Window1()<br /> {<br /> InitializeComponent();<br /> }<br /> <br /> private void Canvas_Loaded(object sender, RoutedEventArgs e)<br /> {<br /> this.Title = &quot;Hello WPF app&quot;;<br /> tbHello.Text = &quot;Hello World!&quot;; //Say hello to wpd TexBloc<br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> window1.xaml<br /> &lt;xml&gt;<br /> &lt;Window x:Class=&quot;HelloWorldWpfApplication.Window1&quot;<br /> xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;<br /> xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;<br /> Title=&quot;Window1&quot; Height=&quot;300&quot; Width=&quot;300&quot;&gt;<br /> &lt;Grid&gt;<br /> &lt;Canvas Loaded=&quot;Canvas_Loaded&quot;&gt;<br /> &lt;TextBlock x:Name=&quot;tbHello&quot; Canvas.Left=&quot;100&quot; Canvas.Top=&quot;100&quot;&gt;&lt;/TextBlock&gt;<br /> &lt;/Canvas&gt;<br /> <br /> &lt;/Grid&gt;<br /> &lt;/Window&gt;<br /> <br /> &lt;/xml&gt;<br /> <br /> ==Other Links==<br /> [http://www.ecma-international.org/publications/standards/Ecma-334.htm ECMA C# and Common Language Infrastructure Standards]&lt;br&gt;<br /> [http://www.mono-project.com/Main_Page Mono] - Ximian Linux .NET Copy&lt;br&gt;<br /> [http://www.gotdotnet.com/ GotDotNet] - Microsoft Site to bridge the gap between .NET team and .NET developers/students&lt;br&gt;<br /> <br /> <br /> <br /> ==Homework==<br /> <br /> #get .Net Framework 4.0 [http://www.microsoft.com/downloads/details.aspx?FamilyID=333325fd-ae52-4e35-b531-508d977d32a6&amp;displaylang=en Microsoft .NET Framework 3.5] and .Net SDK [http://msdn.microsoft.com/en-us/netframework/default.aspx .NET SKD] or Mono [http://www.go-mono.com/mono-downloads/download.html Mono Downloads] or VS2010 (handed out in class) and install it<br /> #write and compile [[Helloworld in csharp]] as a c# console application '''bonus''' make hello world in something besides the console and make it interactive<br /> #Read Learning c# Chapters 1-5 pg 0-46<br /> <br /> *[http://msdn.microsoft.com/en-us/library/aa288463(VS.71).aspx Hello World Tutorial MSDN]<br /> <br /> [[OOP Class1]<br /> <br /> [[Category:IAM Classes]][[Category:Object Oriented Programming]]</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class1&diff=21738 OOP Class1 2013-09-16T18:13:26Z <p>Cameron.Cintron: /* Introduction to Programming languages */</p> <hr /> <div>==Intro to Lab==<br /> *Create student accounts<br /> *Create Student websites<br /> *Show Source Browser already installed in your oop folder<br /> <br /> ==About Class==<br /> ===Technologies===<br /> * C# 4 '''Programming Language''' [http://en.csharp-online.net/CSharp_Language_Specification ECMA-334 C# Language Specification] [http://msdn.microsoft.com/en-us/vcsharp/aa336809.aspx C# language MSDN] <br /> * .NET Framework 3.5 '''Framework API''' http://www.microsoft.com/downloads/details.aspx?FamilyId=333325FD-AE52-4E35-B531-508D977D32A6&amp;displaylang=en<br /> * NET Framework 4.0 http://www.microsoft.com/downloads/details.aspx?FamilyID=9cfb2d51-5ff4-4491-b0e5-b386f32c0992&amp;displaylang=en<br /> * Mono http://www.mono-project.com/Main_Page<br /> <br /> ==Introduction to Programming languages==<br /> <br /> <br /> '''Compliled vs Interpreted Languages'''&lt;br /&gt;<br /> '''Interpreted Languages'''&lt;br /&gt;<br /> &lt;p&gt;<br /> Interpreted langauges read and parse the source input every time a they are executed. After each line is parsed it is converted to machine language and it is executed. Interperted languages are often referd to as scripting languages and are often good for small projects that need to be deployed quickly.&lt;/p&gt;<br /> Interperated Scripting Languages are often used on the web<br /> <br /> Common Interpreted Languages are [http://www.perl.org Perl],[http://www.php.net PHP], [http://www.python.org/ Python] and [http://www.ruby-lang.org/en/ Ruby]<br /> <br /> '''Compiled Languages'''<br /> &lt;br /&gt;<br /> Compiled languages use a complier to read and parse the input source code and convert it into machine language. The output binary file is then excuted. If the source changes the program needs to be recompiled. Complied prorams often execute faster and add extra layer of security becuase the source is not always readily available and executable. Complied code also tends to take up less memory and system resources.<br /> &lt;br /&gt;<br /> Common Client Side <br /> * javascript - ECMA script http://www.ecma-international.org/publications/standards/stnindex.htm<br /> * VBScript - Microsoft scripting version of Visual Basic http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vtoriVBScript.asp<br /> &lt;br /&gt;<br /> Common Server Side Languages<br /> * PHP (recursive acronym for &quot;PHP: Hypertext Preprocessor&quot;) http://www.php.net/<br /> * ASP Active server Pages uses <br /> **jscript (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsoriJScript.asp) **or **vbscript (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vtoriVBScript.asp)<br /> <br /> &lt;br &gt;<br /> HelloWorld in several common programming languages<br /> [[Hello World Languages]]<br /> <br /> ===Why .NET?=== <br /> <br /> *Discussion<br /> <br /> .Net is a platform from Microsoft. It consists of several components. The base of the new platform is the [http://en.wikipedia.org/wiki/Microsoft_.NET] .NET framework. The .NET framework sits on top of the windows(or other operating systems like [http://www.mono-project.com/Main_Page mono]). The .net framework consists of the Common Language Runtime(CLR) and the [http://msdn.microsoft.com/en-us/library/ms229335.aspx Framework Class Library(FCL)]. <br /> <br /> <br /> The CLR is a platform for compiling, debugging and executing .NET applications. Like java the CLR a virtual machine that can better control runtime security, memory management, and threading.<br /> <br /> Here are some examples of the classes available in the .NET framework <br /> <br /> *System Contains fundamental classes and base classes that define commonly used value and reference data types, events and event handlers, interfaces, attributes, and processing exceptions.<br /> *System.Data Consists mostly of the classes that constitute the ADO.NET architecture. The ADO.NET architecture enables you to build components that efficiently manage data from multiple data sources. In a disconnected scenario (such as the Internet), ADO.NET provides the tools to request, update, and reconcile data in multiple tier systems. The ADO.NET architecture is also implemented in client applications, such as Windows Forms, or HTML pages created by ASP.NET.<br /> *System.Data.Common Contains classes shared by the .NET Framework data providers. A .NET Framework data provider describes a collection of classes used to access a data source, such as a database, in the managed space.<br /> *System.Data.SqlClient Encapsulates the .NET Framework Data Provider for SQL Server. The .NET Framework Data Provider for SQL Server describes a collection of classes used to access a SQL Server database in the managed space.<br /> *System.Drawing Provides access to GDI+ basic graphics functionality. More advanced functionality is provided in the<br /> *System.Drawing.Drawing2D Provides advanced 2-dimensional and vector graphics functionality. This namespace includes the gradient brushes, the Matrix class (used to define geometric transforms), and the GraphicsPath class.<br /> *System.Drawing.Imaging Provides advanced GDI+ imaging functionality. Basic graphics functionality is provided by the System.Drawing namespace.<br /> *System.Web Supplies classes and interfaces that enable browser-server communication.<br /> *System.Web.UI Provides classes and interfaces that allow you to create controls and pages that will appear in your Web applications as user interface on a Web page.<br /> System.Web.UI.HtmlControls Consists of a collection of classes that allow you to create HTML server controls on a Web Forms page. HTML server controls run on the server and map directly to standard HTML tags supported by most browsers. This allows you to programmatically control the HTML elements on a Web Forms page.<br /> *System.Web.UI.WebControls Contains classes that allow you to create Web server controls on a Web page. Web server controls run on the server and include form controls such as buttons and text boxes. They also include special purpose controls such as a calendar. Because Web server controls run on the server, you can programmatically control these elements. Web server controls are more abstract than HTML server controls. Their object model does not necessarily reflect HTML syntax.<br /> *System.Windows.Forms Contains classes that support design-time configuration and behavior for Windows Forms components.<br /> Full List with descriptions http://msdn.microsoft.com/en-us/library/ms229335.aspx<br /> <br /> Unlike Java the Microsoft CLR supports multiple languages.<br /> <br /> Sun and Microsoft have different programing philosophies.<br /> Java write once (in java) run anywhere.<br /> CLR write in any CLR language and run on .NET<br /> The CLR from Microsoft supports several languages.<br /> <br /> * C# - java like language pronounced C Sharp (the language we will use for this course)<br /> * VB.NET - Visual Basic .NET<br /> * JScript<br /> * J# - Microsoft's Java-language<br /> * third party languages (cobol,eiffel,pascal,perl) [http://msdn.microsoft.com/vstudio/partners/language/default.asp Programming Language Partners] <br /> <br /> The CLR compiles the .NET languages into MS Intermediate Language (MSIL) which is similar to java's object code. It is an intermediary step between programming language and machine code. The MSIL allows .NET to support multiple programming languages. MSIL code is further compiled by the CLR at run time into machine code. This is known as JIT compilation or Just In Time.<br /> <br /> ===.NET Applications===<br /> <br /> * Console Applications<br /> * Windows Forms http://windowsclient.net/getstarted/<br /> * Windows Presentation Forms http://windowsclient.net/getstarted/ http://windowsclient.net/learn/videos_wpf.aspx<br /> * Web Forms http://asp.net/get-started/<br /> * Web Services<br /> * XNA http://creators.xna.com/en-US/quickstart_main<br /> <br /> *[http://msdn.microsoft.com/en-us/library/aa288463(VS.71).aspx Hello World Tutorial MSDN]<br /> <br /> Hello world in C# for console really simple<br /> &lt;csharp&gt;using System;<br /> namespace HelloClass<br /> {<br /> class HelloWorld<br /> {<br /> //All Console Apps start with Main Method<br /> public static void Main()<br /> {<br /> Console.WriteLine(&quot;Hello World!&quot;);<br /> <br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> ==Hello Console==<br /> <br /> &lt;csharp&gt;using System;<br /> using System.Collections.Generic;<br /> using System.Linq;<br /> using System.Text;<br /> <br /> namespace HelloWorldConsole<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Hello World!&quot;); //Write Hello World! to the console standard out<br /> }<br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> <br /> http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class1/HelloWorldConsole/HelloWorldConsole/Program.cs<br /> <br /> MSIL<br /> &lt;csharp&gt;.method public hidebysig static void Main() cil managed<br /> {<br /> .entrypoint<br /> // Code size 11 (0xb)<br /> .maxstack 1<br /> IL_0000: ldstr &quot;Hello World!&quot;<br /> IL_0005: call void [mscorlib]System.Console::WriteLine(string)<br /> IL_000a: ret<br /> } // end of method HelloWorldConsole::Main<br /> &lt;/csharp&gt;<br /> Fully Disassembled hello.cs<br /> <br /> ==Hello WinForms==<br /> form1.cs<br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.ComponentModel;<br /> using System.Data;<br /> using System.Drawing;<br /> using System.Linq;<br /> using System.Text;<br /> using System.Windows.Forms;<br /> <br /> namespace HelloWorldWindowsForms<br /> {<br /> public partial class Form1 : Form<br /> {<br /> public Form1()<br /> {<br /> InitializeComponent();<br /> }<br /> <br /> private void Form1_Load(object sender, EventArgs e)<br /> {<br /> this.Text = &quot;Hello World App&quot;; //Change the title of the form<br /> //yeah i know i could have done it in the designer<br /> <br /> label1.Text = &quot;Hello World!&quot;; //Say Hello in a Label<br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class1/HelloWorldWindowsForms/HelloWorldWindowsForms/Form1.cs<br /> <br /> ==Helloworld! WPF==<br /> <br /> Window1.xaml.cs<br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Linq;<br /> using System.Text;<br /> using System.Windows;<br /> using System.Windows.Controls;<br /> using System.Windows.Data;<br /> using System.Windows.Documents;<br /> using System.Windows.Input;<br /> using System.Windows.Media;<br /> using System.Windows.Media.Imaging;<br /> using System.Windows.Navigation;<br /> using System.Windows.Shapes;<br /> <br /> namespace HelloWorldWpfApplication<br /> {<br /> /// &lt;summary&gt;<br /> /// Interaction logic for Window1.xaml<br /> /// &lt;/summary&gt;<br /> public partial class Window1 : Window<br /> {<br /> public Window1()<br /> {<br /> InitializeComponent();<br /> }<br /> <br /> private void Canvas_Loaded(object sender, RoutedEventArgs e)<br /> {<br /> this.Title = &quot;Hello WPF app&quot;;<br /> tbHello.Text = &quot;Hello World!&quot;; //Say hello to wpd TexBloc<br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> window1.xaml<br /> &lt;xml&gt;<br /> &lt;Window x:Class=&quot;HelloWorldWpfApplication.Window1&quot;<br /> xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;<br /> xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;<br /> Title=&quot;Window1&quot; Height=&quot;300&quot; Width=&quot;300&quot;&gt;<br /> &lt;Grid&gt;<br /> &lt;Canvas Loaded=&quot;Canvas_Loaded&quot;&gt;<br /> &lt;TextBlock x:Name=&quot;tbHello&quot; Canvas.Left=&quot;100&quot; Canvas.Top=&quot;100&quot;&gt;&lt;/TextBlock&gt;<br /> &lt;/Canvas&gt;<br /> <br /> &lt;/Grid&gt;<br /> &lt;/Window&gt;<br /> <br /> &lt;/xml&gt;<br /> <br /> ==Other Links==<br /> [http://www.ecma-international.org/publications/standards/Ecma-334.htm ECMA C# and Common Language Infrastructure Standards]&lt;br&gt;<br /> [http://www.mono-project.com/Main_Page Mono] - Ximian Linux .NET Copy&lt;br&gt;<br /> [http://www.gotdotnet.com/ GotDotNet] - Microsoft Site to bridge the gap between .NET team and .NET developers/students&lt;br&gt;<br /> <br /> <br /> <br /> ==Homework==<br /> <br /> #get .Net Framework 4.0 [http://www.microsoft.com/downloads/details.aspx?FamilyID=333325fd-ae52-4e35-b531-508d977d32a6&amp;displaylang=en Microsoft .NET Framework 3.5] and .Net SDK [http://msdn.microsoft.com/en-us/netframework/default.aspx .NET SKD] or Mono [http://www.go-mono.com/mono-downloads/download.html Mono Downloads] or VS2010 (handed out in class) and install it<br /> #write and compile [[Helloworld in csharp]] as a c# console application '''bonus''' make hello world in something besides the console and make it interactive<br /> #Read Learning c# Chapters 1-5 pg 0-46<br /> <br /> *[http://msdn.microsoft.com/en-us/library/aa288463(VS.71).aspx Hello World Tutorial MSDN]<br /> <br /> [[OOP Class1]<br /> <br /> [[Category:IAM Classes]][[Category:Object Oriented Programming]]</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class1&diff=21737 OOP Class1 2013-09-16T18:12:22Z <p>Cameron.Cintron: /* Introduction to Programming languages */</p> <hr /> <div>==Intro to Lab==<br /> *Create student accounts<br /> *Create Student websites<br /> *Show Source Browser already installed in your oop folder<br /> <br /> ==About Class==<br /> ===Technologies===<br /> * C# 4 '''Programming Language''' [http://en.csharp-online.net/CSharp_Language_Specification ECMA-334 C# Language Specification] [http://msdn.microsoft.com/en-us/vcsharp/aa336809.aspx C# language MSDN] <br /> * .NET Framework 3.5 '''Framework API''' http://www.microsoft.com/downloads/details.aspx?FamilyId=333325FD-AE52-4E35-B531-508D977D32A6&amp;displaylang=en<br /> * NET Framework 4.0 http://www.microsoft.com/downloads/details.aspx?FamilyID=9cfb2d51-5ff4-4491-b0e5-b386f32c0992&amp;displaylang=en<br /> * Mono http://www.mono-project.com/Main_Page<br /> <br /> ==Introduction to Programming languages==<br /> <br /> <br /> '''Compliled vs Interpreted Languages'''&lt;br /&gt;<br /> '''Interpreted Languages'''&lt;br /&gt;<br /> &lt;p&gt;<br /> Interpreted langauges read and parse the source input every time a they are executed. After each line is parsed it is converted to machine language and it is executed. Interperted languages are often referd to as scripting languages and are often good for small projects that need to be deployed quickly.&lt;/p&gt;<br /> Interperated Scripting Languages are often used on the web<br /> <br /> Common Interpreted Languages are [http://www.perl.org Perl],[http://www.php.net PHP], [http://www.python.org/ Python] and [http://www.ruby-lang.org/en/ Ruby]<br /> <br /> '''Compiled Languages'''<br /> &lt;br /&gt;<br /> Compiled languages use a complier to read and parse the input source code and convert it into machine language. The output binary file is then excuted. If the source changes the program needs to be recompiled. Complied prorams often execute faster and add extra layer of security becuase the source is not always readily available and executable. Complied code also tends to take up less memory and system resources.<br /> &lt;br /&gt;<br /> Common Client Side <br /> * javascript - ECMA script http://www.ecma-international.org/publications/standards/stnindex.htm<br /> * VBScript - Microsoft scripting version of Visual Basic http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vtoriVBScript.asp<br /> &lt;br /&gt;<br /> Common Server Side Languages<br /> * PHP (recursive acronym for &quot;PHP: Hypertext Preprocessor&quot;) http://www.php.net/<br /> * ASP Active server Pages uses <br /> **jscript (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsoriJScript.asp) **or **vbscript (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vtoriVBScript.asp)<br /> <br /> &lt;br &gt;<br /> HelloWorld in several common programming languages<br /> [[Hello World Languages]]<br /> <br /> ===Why .NET?=== <br /> <br /> *Discussion<br /> <br /> .Net is a platform from Microsoft. It consists of several components. The base of the new platform is the [http://en.wikipedia.org/wiki/Microsoft_.NET] .NET framework. The .NET framework sits on top of the windows(or other operating systems like [http://www.mono-project.com/Main_Page mono]). The .net framework consists of the Common Language Runtime(CLR) and the [http://msdn.microsoft.com/en-us/library/ms229335.aspx Framework Class Library(FCL)]. <br /> <br /> <br /> The CLR is a platform for compiling, debugging and executing .NET applications. Like java the CLR a virtual machine that can better control runtime security, memory management, and threading.<br /> <br /> Here are some examples of the classes available in the .NET framework <br /> <br /> *System Contains fundamental classes and base classes that define commonly used value and reference data types, events and event handlers, interfaces, attributes, and processing exceptions.<br /> *System.Data Consists mostly of the classes that constitute the ADO.NET architecture. The ADO.NET architecture enables you to build components that efficiently manage data from multiple data sources. In a disconnected scenario (such as the Internet), ADO.NET provides the tools to request, update, and reconcile data in multiple tier systems. The ADO.NET architecture is also implemented in client applications, such as Windows Forms, or HTML pages created by ASP.NET.<br /> *System.Data.Common Contains classes shared by the .NET Framework data providers. A .NET Framework data provider describes a collection of classes used to access a data source, such as a database, in the managed space.<br /> *System.Data.SqlClient Encapsulates the .NET Framework Data Provider for SQL Server. The .NET Framework Data Provider for SQL Server describes a collection of classes used to access a SQL Server database in the managed space.<br /> *System.Drawing Provides access to GDI+ basic graphics functionality. More advanced functionality is provided in the<br /> *System.Drawing.Drawing2D Provides advanced 2-dimensional and vector graphics functionality. This namespace includes the gradient brushes, the Matrix class (used to define geometric transforms), and the GraphicsPath class.<br /> *System.Drawing.Imaging Provides advanced GDI+ imaging functionality. Basic graphics functionality is provided by the System.Drawing namespace.<br /> *System.Web Supplies classes and interfaces that enable browser-server communication.<br /> *System.Web.UI Provides classes and interfaces that allow you to create controls and pages that will appear in your Web applications as user interface on a Web page.<br /> System.Web.UI.HtmlControls Consists of a collection of classes that allow you to create HTML server controls on a Web Forms page. HTML server controls run on the server and map directly to standard HTML tags supported by most browsers. This allows you to programmatically control the HTML elements on a Web Forms page.<br /> *System.Web.UI.WebControls Contains classes that allow you to create Web server controls on a Web page. Web server controls run on the server and include form controls such as buttons and text boxes. They also include special purpose controls such as a calendar. Because Web server controls run on the server, you can programmatically control these elements. Web server controls are more abstract than HTML server controls. Their object model does not necessarily reflect HTML syntax.<br /> *System.Windows.Forms Contains classes that support design-time configuration and behavior for Windows Forms components.<br /> Full List with descriptions http://msdn.microsoft.com/en-us/library/ms229335.aspx<br /> <br /> Unlike Java the Microsoft CLR supports multiple languages.<br /> <br /> Sun and Microsoft have different programing philosophies.<br /> Java write once (in java) run anywhere.<br /> CLR write in any CLR language and run on .NET<br /> The CLR from Microsoft supports several languages.<br /> <br /> * C# - java like language pronounced C Sharp (the language we will use for this course)<br /> * VB.NET - Visual Basic .NET<br /> * JScript<br /> * J# - Microsoft's Java-language<br /> * third party languages (cobol,eiffel,pascal,perl) [http://msdn.microsoft.com/vstudio/partners/language/default.asp Programming Language Partners] <br /> <br /> The CLR compiles the .NET languages into MS Intermediate Language (MSIL) which is similar to java's object code. It is an intermediary step between programming language and machine code. The MSIL allows .NET to support multiple programming languages. MSIL code is further compiled by the CLR at run time into machine code. This is known as JIT compilation or Just In Time.<br /> <br /> ===.NET Applications===<br /> <br /> * Console Applications<br /> * Windows Forms http://windowsclient.net/getstarted/<br /> * Windows Presentation Forms http://windowsclient.net/getstarted/ http://windowsclient.net/learn/videos_wpf.aspx<br /> * Web Forms http://asp.net/get-started/<br /> * Web Services<br /> * XNA http://creators.xna.com/en-US/quickstart_main<br /> <br /> *[http://msdn.microsoft.com/en-us/library/aa288463(VS.71).aspx Hello World Tutorial MSDN]<br /> <br /> Hello world in C# for console really simple<br /> &lt;csharp&gt;using System;<br /> namespace HelloClass<br /> {<br /> class HelloWorld<br /> {<br /> //All Console Apps start with Main Method<br /> public static void Main()<br /> {<br /> Console.WriteLine(&quot;Hello World!&quot;);<br /> <br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> ===Video===<br /> <br /> &lt;html&gt;<br /> &lt;script type='text/javascript' src='http://iam.colum.edu/videotutorials/mediaplayer-5.2/swfobject.js'&gt;&lt;/script&gt; <br /> &lt;div id='mediaspace2'&gt;This text will be replaced&lt;/div&gt; <br /> &lt;script type='text/javascript'&gt;<br /> var so = new SWFObject('http://iam.colum.edu/videotutorials/mediaplayer-5.2/player.swf','mpl','800','600','9');so.addParam('allowfullscreen','true')<br /> ;so.addParam('allowscriptaccess','always');<br /> so.addParam('wmode','opaque');<br /> so.addVariable('file','http://iam.colum.edu/screenz/FA13/OOP_Class1_JM/OOP_Class1_JM.mp4');<br /> so.addVariable('autostart','false');<br /> so.write('mediaspace2');<br /> <br /> &lt;/script&gt;<br /> <br /> &lt;/html&gt;<br /> <br /> ==Hello Console==<br /> <br /> &lt;csharp&gt;using System;<br /> using System.Collections.Generic;<br /> using System.Linq;<br /> using System.Text;<br /> <br /> namespace HelloWorldConsole<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Hello World!&quot;); //Write Hello World! to the console standard out<br /> }<br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> <br /> http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class1/HelloWorldConsole/HelloWorldConsole/Program.cs<br /> <br /> MSIL<br /> &lt;csharp&gt;.method public hidebysig static void Main() cil managed<br /> {<br /> .entrypoint<br /> // Code size 11 (0xb)<br /> .maxstack 1<br /> IL_0000: ldstr &quot;Hello World!&quot;<br /> IL_0005: call void [mscorlib]System.Console::WriteLine(string)<br /> IL_000a: ret<br /> } // end of method HelloWorldConsole::Main<br /> &lt;/csharp&gt;<br /> Fully Disassembled hello.cs<br /> <br /> ==Hello WinForms==<br /> form1.cs<br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.ComponentModel;<br /> using System.Data;<br /> using System.Drawing;<br /> using System.Linq;<br /> using System.Text;<br /> using System.Windows.Forms;<br /> <br /> namespace HelloWorldWindowsForms<br /> {<br /> public partial class Form1 : Form<br /> {<br /> public Form1()<br /> {<br /> InitializeComponent();<br /> }<br /> <br /> private void Form1_Load(object sender, EventArgs e)<br /> {<br /> this.Text = &quot;Hello World App&quot;; //Change the title of the form<br /> //yeah i know i could have done it in the designer<br /> <br /> label1.Text = &quot;Hello World!&quot;; //Say Hello in a Label<br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class1/HelloWorldWindowsForms/HelloWorldWindowsForms/Form1.cs<br /> <br /> ==Helloworld! WPF==<br /> <br /> Window1.xaml.cs<br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Linq;<br /> using System.Text;<br /> using System.Windows;<br /> using System.Windows.Controls;<br /> using System.Windows.Data;<br /> using System.Windows.Documents;<br /> using System.Windows.Input;<br /> using System.Windows.Media;<br /> using System.Windows.Media.Imaging;<br /> using System.Windows.Navigation;<br /> using System.Windows.Shapes;<br /> <br /> namespace HelloWorldWpfApplication<br /> {<br /> /// &lt;summary&gt;<br /> /// Interaction logic for Window1.xaml<br /> /// &lt;/summary&gt;<br /> public partial class Window1 : Window<br /> {<br /> public Window1()<br /> {<br /> InitializeComponent();<br /> }<br /> <br /> private void Canvas_Loaded(object sender, RoutedEventArgs e)<br /> {<br /> this.Title = &quot;Hello WPF app&quot;;<br /> tbHello.Text = &quot;Hello World!&quot;; //Say hello to wpd TexBloc<br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> window1.xaml<br /> &lt;xml&gt;<br /> &lt;Window x:Class=&quot;HelloWorldWpfApplication.Window1&quot;<br /> xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;<br /> xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;<br /> Title=&quot;Window1&quot; Height=&quot;300&quot; Width=&quot;300&quot;&gt;<br /> &lt;Grid&gt;<br /> &lt;Canvas Loaded=&quot;Canvas_Loaded&quot;&gt;<br /> &lt;TextBlock x:Name=&quot;tbHello&quot; Canvas.Left=&quot;100&quot; Canvas.Top=&quot;100&quot;&gt;&lt;/TextBlock&gt;<br /> &lt;/Canvas&gt;<br /> <br /> &lt;/Grid&gt;<br /> &lt;/Window&gt;<br /> <br /> &lt;/xml&gt;<br /> <br /> ==Other Links==<br /> [http://www.ecma-international.org/publications/standards/Ecma-334.htm ECMA C# and Common Language Infrastructure Standards]&lt;br&gt;<br /> [http://www.mono-project.com/Main_Page Mono] - Ximian Linux .NET Copy&lt;br&gt;<br /> [http://www.gotdotnet.com/ GotDotNet] - Microsoft Site to bridge the gap between .NET team and .NET developers/students&lt;br&gt;<br /> <br /> <br /> <br /> ==Homework==<br /> <br /> #get .Net Framework 4.0 [http://www.microsoft.com/downloads/details.aspx?FamilyID=333325fd-ae52-4e35-b531-508d977d32a6&amp;displaylang=en Microsoft .NET Framework 3.5] and .Net SDK [http://msdn.microsoft.com/en-us/netframework/default.aspx .NET SKD] or Mono [http://www.go-mono.com/mono-downloads/download.html Mono Downloads] or VS2010 (handed out in class) and install it<br /> #write and compile [[Helloworld in csharp]] as a c# console application '''bonus''' make hello world in something besides the console and make it interactive<br /> #Read Learning c# Chapters 1-5 pg 0-46<br /> <br /> *[http://msdn.microsoft.com/en-us/library/aa288463(VS.71).aspx Hello World Tutorial MSDN]<br /> <br /> [[OOP Class1]<br /> <br /> [[Category:IAM Classes]][[Category:Object Oriented Programming]]</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class2&diff=21736 OOP Class2 2013-09-16T18:07:45Z <p>Cameron.Cintron: /* Video */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> ==Posting home work and website==<br /> <br /> =C# fundamentals=<br /> <br /> Questions from week 1 reading.<br /> discussion<br /> <br /> Some pages comparing c# to other languages<br /> <br /> A Comparative Overview of C# http://genamics.com/developer/csharp_comparative.htm<br /> <br /> C# and Java: Comparing Programming Languages http://msdn.microsoft.com/en-us/library/ms836794.aspx<br /> <br /> ==Terms==<br /> <br /> CLR<br /> :Common Language Runtime<br /> namespace<br /> :organizing classes with hierarchy <br /> keyword<br /> :reserved system word<br /> MSIL<br /> :MicroSoft Intermediary Language<br /> JIT<br /> :Just In Time compilation @ first run<br /> <br /> ==Everything is an Object==<br /> In c# everything is an object. And all objects inherit from the object class.<br /> <br /> [http://quickstarts.asp.net/QuickStartv20/util/classbrowser.aspx See object in the classbrowser]<br /> <br /> Since all objects inherit from the object class they all have some the basic functionality like a method called ToString();<br /> <br /> [http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class2/FromMono See the source for object.cs from mono] <br /> <br /> <br /> ==Basic Data Types==<br /> <br /> C# is a strongly typed language. This means every object in C# must be declared to be of a specific type. All of c# basic varible type inherit from [http://msdn2.microsoft.com/en-us/library/system.object.aspx System.Object]<br /> <br /> {{.NET Data Types}}<br /> <br /> Variables must be declared with an identifier and then initialized.<br /> <br /> ===Declaration===<br /> <br /> Declaration sets aside a named section of memory the is the proper size to hold the declared type. At this point the variable contains nothing.<br /> <br /> &lt;csharp&gt;// declare a variable<br /> int firstInt; //declares a vaiable of type int<br /> string myString; //declares a vaiable of type string&lt;/csharp&gt;<br /> <br /> ===Initialization===<br /> <br /> Initialization actually sets the variables value<br /> <br /> &lt;csharp&gt;// initialize the variable<br /> firstInt = 1;<br /> myString = &quot;Hello!&quot;;&lt;/csharp&gt;<br /> <br /> Initialization uses the assignment operator to set the value of a variable<br /> <br /> ===Assignment===<br /> The Assignment '''operator''' in c# is the '=' sign. You can assign variables like this...<br /> <br /> ==Assignment==<br /> The Assignment operator in c# is the '=' sign. You can assign variables like this...<br /> We'll learn more about operators later.<br /> <br /> other ways to do it<br /> <br /> &lt;csharp&gt;// declare some variables<br /> int secondInt, thirdInt, fourthInt;<br /> secondInt = 2;<br /> thirdInt = 3;<br /> fourthInt = 4;<br /> <br /> //declare and initialize variables in one line<br /> int myNegativeInt = -2147483648;&lt;/csharp&gt;<br /> <br /> In c# variables cannot be used unil they are initalized.<br /> For example<br /> <br /> &lt;csharp&gt;int UsedBeforeInit;<br /> Console.WriteLine(UsedBeforeInit);&lt;/csharp&gt;<br /> <br /> will produce<br /> <br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> <br /> ==Compiler Errors==<br /> error<br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> file Line .Net Framework error # and description<br /> <br /> <br /> <br /> [[Csharp warning CS0168: The variable 'NeverUsed' is declared but never used]]<br /> <br /> <br /> <br /> <br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit.cs UsedBeforeInit.cs] - example of misused variable&lt;br /&gt;<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit_Fixed.cs UsedBeforeInit_Fixed.cs] - all beter now source&lt;br /&gt;<br /> <br /> More examples of built in types<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/csharpfundamentals/1x1.cs 1x1.cs] C# intrinsic types from Learn-C-Sharp.<br /> variable.aspx - example from book aspx page View Source<br /> variable2.aspx = example from book errors View Source<br /> <br /> ==Variable Names==<br /> <br /> Variable should be named with meaningful names.<br /> <br /> for exmaple <br /> :z = x * y;<br /> <br /> does not convey any meaning<br /> <br /> but<br /> :distance = speed * time;<br /> <br /> does convey meaning.<br /> If varibales are named properly it can make your code mush easier to read.<br /> <br /> ==Naming conventions==<br /> Name variables intelligently.&lt;br&gt;<br /> Name variables with names that have meaning.&lt;br&gt;<br /> <br /> ===Hungarian Notation===<br /> Hungarian notation id a popular notation system used be many C, C++ and VB programmers. It was originally devised in Charles Simonyi's doctoral thesis, &quot;Meta-Programming: A Software Production Method.&quot; Hungarian notation specifies that a prefix be added to each variable that indicated that variables type. It also specifies sometimes adding a suffice to clarify variables meaning. In the early 1980's Microsoft adopted this notation system.<br /> <br /> <br /> ie... intHitCounter, intHitsPerMonthMax <br /> <br /> [http://msdn.microsoft.com/en-us/library/aa260976(VS.60).aspx Hungarian Notation - Charles Simonyi Microsoft]<br /> <br /> http://msdn.microsoft.com/en-us/library/ms229045.aspx<br /> <br /> '''PascalNotation'''<br /> Capitalize first Letter and then the first letter on each word. &lt;br&gt;<br /> ie... PascalNotation, IntVarName<br /> <br /> Use on method names method names.<br /> <br /> '''camelNotation'''<br /> Lower case first letter and then capitalize the first letter of each word&lt;br&gt;<br /> ie... camelNotation, intVarName<br /> <br /> use for variable names<br /> <br /> Other Coding Techniques and practices&lt;br&gt;<br /> [http://msdn.microsoft.com/en-us/library/ms229002.aspx .NET Framework Developer's Guide<br /> Guidelines for Names]&lt;br&gt;<br /> [http://www-106.ibm.com/developerworks/eserver/articles/hook_duttaC.html?ca=dgr-lnxw06BestC IBM Best Practices for Programming in C]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html GNU Coding Standards]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html#Names GNU Naming conventions]&lt;br&gt;<br /> More Types<br /> <br /> ==Operators==<br /> <br /> ECMA-334 Operators and punctuators<br /> <br /> C# uses the equals = sign for Assignment<br /> <br /> int myVar = 15; //sets the value of myVar to 15<br /> <br /> ===Mathematical Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |+ ||addition<br /> |-<br /> |- || subtraction<br /> |-<br /> |* || multiplication<br /> |-<br /> |/ || division<br /> |-<br /> |% || modulus remainder Ask Dr.Math What is Modulus?<br /> |}<br /> <br /> ===Increment Decrement Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |++ || increment same as foo = foo + 1<br /> |-<br /> | -- || decrement same as foo = foo - 1<br /> |-<br /> |+= || calculate and reassign addition<br /> |-<br /> | -= || calculate and reassign subtraction<br /> |-<br /> |*= || calculate and reassign multiplication<br /> |-<br /> |/= || calculate and reassign division<br /> |-<br /> |%= || calculate and reassign modulus<br /> |-<br /> |y= x++ || assignment prefix y is assigned to x and then x in incremented<br /> |-<br /> |y= ++x || assignment postfix x is incremented and then assigned to y<br /> |}<br /> <br /> ===Operator Precedence===<br /> Evaluated First<br /> <br /> * ++,--,unary-<br /> * *,/,%<br /> * +,-<br /> <br /> Evaluated Last<br /> <br /> * =,+=,-=,*=,etc<br /> <br /> <br /> {{csharp strings}}<br /> {{csharp string functions}}<br /> <br /> ==Short Assignment==<br /> Short in class Assignment<br /> In class assignment 10-15 mins<br /> Build a c# console app (remember to take a top down aproach start small with something you know maybe start with hello world)<br /> * Declare and initialize two integers<br /> * Display their values using Console.WriteLine<br /> * Declare a third integer and initialize it with the sum of the first two integers<br /> * Output the value of the third integer<br /> <br /> <br /> Top down development with comments [http://iam.colum.edu/oop/classsource/class2/topdown.aspx topdown.aspx]<br /> <br /> Fully implemented Console adding program [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/add.cs add.cs]<br /> <br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> <br /> namespace Hello<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Super Cool Calculatorizer&quot;);<br /> <br /> //Declare two variables<br /> int intOne;<br /> int intTwo;<br /> int intSum;<br /> <br /> //intialize the two variables<br /> intOne = 47;<br /> intTwo = 2;<br /> <br /> //Lets test the values<br /> Console.Write(&quot;Enter a integer: &quot;);<br /> intOne = int.Parse(Console.ReadLine()); //set the value of intOne <br /> //to what was typed in the console<br /> Console.Write(&quot;Enter another integer: &quot;);<br /> intTwo = int.Parse(Console.ReadLine()); //int.Parse attempts to parse a string<br /> //and convert it to an int<br /> <br /> intSum = intOne + intTwo;<br /> <br /> Console.WriteLine(&quot;intTwo + intTwo = &quot; + intSum);<br /> <br /> Console.ReadKey();<br /> <br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> ==Constants==<br /> <br /> Constants are datatypes that will be assigned a value that will be constant thought the executing of the code. You cannot change constants once they have been assigned a value.<br /> syntax<br /> <br /> &lt;csharp&gt;const type identifier = value;&lt;/csharp&gt;<br /> <br /> <br /> example<br /> <br /> &lt;csharp&gt;const int freezingPoint = 32;<br /> const int freezingPointMetric = 0;<br /> const float pi = 3.141592&lt;/csharp&gt;<br /> <br /> <br /> [[OOP Arrays]]<br /> {{csharp arrays}}<br /> <br /> <br /> ==Simple Branching==<br /> <br /> ===if===<br /> syntax<br /> <br /> &lt;csharp&gt;if (expression)<br /> // statement<br /> <br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> else {<br /> // statements<br /> }&lt;/csharp&gt;<br /> <br /> ==HomeWork==<br /> *Learning c#<br /> *Chapter 5, Chapter 6<br /> <br /> <br /> Create a simple text game that asks three questions and sets three variables. There should be a fourth variable that counts the number of correct answers. The program should run in the console and use:<br /> <br /> *Console.WriteLine<br /> *Console.ReadLine<br /> *ints, strings and ifs<br /> <br /> Analysis of Homework Project<br /> *On very structured programs like this one analysis is quite easy<br /> ** Start by identifying the steps<br /> ** Add [http://en.wikipedia.org/wiki/Pseudocode Pseudocode] as c# comments for each step<br /> ** Fill in the real syntax for each step and compile each time to make sure nothing breaks (I like to call this baby steps and I like to use this technique whenever I'm trying to implement something that is completely new to me)<br /> <br /> The pseudocode might look something like<br /> &lt;csharp&gt;using System;<br /> namespace HelloVariables<br /> {<br /> class ThreeQuestions<br /> {<br /> public static void Main()<br /> {<br /> Console.WriteLine(&quot;3 Questions&quot;);<br /> //A simple game that asks three questions and checks the answers. If the question is answered correctly we will award 1 point<br /> <br /> //Declare Variables<br /> <br /> //Ask Question 1<br /> <br /> //Read Answer<br /> <br /> //Check Answer and add 1 to points is correct<br /> <br /> //Repeat with Questions 2 and 3<br /> <br /> //Display Percent Correct<br /> <br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> ==Video==<br /> &lt;html&gt;<br /> &lt;script type='text/javascript' src='http://iam.colum.edu/videotutorials/mediaplayer-5.2/swfobject.js'&gt;&lt;/script&gt; <br /> &lt;div id='mediaspace2'&gt;This text will be replaced&lt;/div&gt; <br /> &lt;script type='text/javascript'&gt;<br /> var so = new SWFObject('http://iam.colum.edu/videotutorials/mediaplayer-5.2/player.swf','mpl','800','600','9');so.addParam('allowfullscreen','true')<br /> ;so.addParam('allowscriptaccess','always');<br /> so.addParam('wmode','opaque');<br /> so.addVariable('file','http://iam.colum.edu/screenz/FA13/OOP_Week_2/OOP_Week_2.mp4');<br /> so.addVariable('autostart','false');<br /> so.write('mediaspace2');<br /> <br /> &lt;/script&gt;<br /> <br /> &lt;/html&gt;</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class2&diff=21735 OOP Class2 2013-09-16T18:03:12Z <p>Cameron.Cintron: /* Video */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> ==Posting home work and website==<br /> <br /> =C# fundamentals=<br /> <br /> Questions from week 1 reading.<br /> discussion<br /> <br /> Some pages comparing c# to other languages<br /> <br /> A Comparative Overview of C# http://genamics.com/developer/csharp_comparative.htm<br /> <br /> C# and Java: Comparing Programming Languages http://msdn.microsoft.com/en-us/library/ms836794.aspx<br /> <br /> ==Terms==<br /> <br /> CLR<br /> :Common Language Runtime<br /> namespace<br /> :organizing classes with hierarchy <br /> keyword<br /> :reserved system word<br /> MSIL<br /> :MicroSoft Intermediary Language<br /> JIT<br /> :Just In Time compilation @ first run<br /> <br /> ==Everything is an Object==<br /> In c# everything is an object. And all objects inherit from the object class.<br /> <br /> [http://quickstarts.asp.net/QuickStartv20/util/classbrowser.aspx See object in the classbrowser]<br /> <br /> Since all objects inherit from the object class they all have some the basic functionality like a method called ToString();<br /> <br /> [http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class2/FromMono See the source for object.cs from mono] <br /> <br /> <br /> ==Basic Data Types==<br /> <br /> C# is a strongly typed language. This means every object in C# must be declared to be of a specific type. All of c# basic varible type inherit from [http://msdn2.microsoft.com/en-us/library/system.object.aspx System.Object]<br /> <br /> {{.NET Data Types}}<br /> <br /> Variables must be declared with an identifier and then initialized.<br /> <br /> ===Declaration===<br /> <br /> Declaration sets aside a named section of memory the is the proper size to hold the declared type. At this point the variable contains nothing.<br /> <br /> &lt;csharp&gt;// declare a variable<br /> int firstInt; //declares a vaiable of type int<br /> string myString; //declares a vaiable of type string&lt;/csharp&gt;<br /> <br /> ===Initialization===<br /> <br /> Initialization actually sets the variables value<br /> <br /> &lt;csharp&gt;// initialize the variable<br /> firstInt = 1;<br /> myString = &quot;Hello!&quot;;&lt;/csharp&gt;<br /> <br /> Initialization uses the assignment operator to set the value of a variable<br /> <br /> ===Assignment===<br /> The Assignment '''operator''' in c# is the '=' sign. You can assign variables like this...<br /> <br /> ==Assignment==<br /> The Assignment operator in c# is the '=' sign. You can assign variables like this...<br /> We'll learn more about operators later.<br /> <br /> other ways to do it<br /> <br /> &lt;csharp&gt;// declare some variables<br /> int secondInt, thirdInt, fourthInt;<br /> secondInt = 2;<br /> thirdInt = 3;<br /> fourthInt = 4;<br /> <br /> //declare and initialize variables in one line<br /> int myNegativeInt = -2147483648;&lt;/csharp&gt;<br /> <br /> In c# variables cannot be used unil they are initalized.<br /> For example<br /> <br /> &lt;csharp&gt;int UsedBeforeInit;<br /> Console.WriteLine(UsedBeforeInit);&lt;/csharp&gt;<br /> <br /> will produce<br /> <br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> <br /> ==Compiler Errors==<br /> error<br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> file Line .Net Framework error # and description<br /> <br /> <br /> <br /> [[Csharp warning CS0168: The variable 'NeverUsed' is declared but never used]]<br /> <br /> <br /> <br /> <br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit.cs UsedBeforeInit.cs] - example of misused variable&lt;br /&gt;<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit_Fixed.cs UsedBeforeInit_Fixed.cs] - all beter now source&lt;br /&gt;<br /> <br /> More examples of built in types<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/csharpfundamentals/1x1.cs 1x1.cs] C# intrinsic types from Learn-C-Sharp.<br /> variable.aspx - example from book aspx page View Source<br /> variable2.aspx = example from book errors View Source<br /> <br /> ==Variable Names==<br /> <br /> Variable should be named with meaningful names.<br /> <br /> for exmaple <br /> :z = x * y;<br /> <br /> does not convey any meaning<br /> <br /> but<br /> :distance = speed * time;<br /> <br /> does convey meaning.<br /> If varibales are named properly it can make your code mush easier to read.<br /> <br /> ==Naming conventions==<br /> Name variables intelligently.&lt;br&gt;<br /> Name variables with names that have meaning.&lt;br&gt;<br /> <br /> ===Hungarian Notation===<br /> Hungarian notation id a popular notation system used be many C, C++ and VB programmers. It was originally devised in Charles Simonyi's doctoral thesis, &quot;Meta-Programming: A Software Production Method.&quot; Hungarian notation specifies that a prefix be added to each variable that indicated that variables type. It also specifies sometimes adding a suffice to clarify variables meaning. In the early 1980's Microsoft adopted this notation system.<br /> <br /> <br /> ie... intHitCounter, intHitsPerMonthMax <br /> <br /> [http://msdn.microsoft.com/en-us/library/aa260976(VS.60).aspx Hungarian Notation - Charles Simonyi Microsoft]<br /> <br /> http://msdn.microsoft.com/en-us/library/ms229045.aspx<br /> <br /> '''PascalNotation'''<br /> Capitalize first Letter and then the first letter on each word. &lt;br&gt;<br /> ie... PascalNotation, IntVarName<br /> <br /> Use on method names method names.<br /> <br /> '''camelNotation'''<br /> Lower case first letter and then capitalize the first letter of each word&lt;br&gt;<br /> ie... camelNotation, intVarName<br /> <br /> use for variable names<br /> <br /> Other Coding Techniques and practices&lt;br&gt;<br /> [http://msdn.microsoft.com/en-us/library/ms229002.aspx .NET Framework Developer's Guide<br /> Guidelines for Names]&lt;br&gt;<br /> [http://www-106.ibm.com/developerworks/eserver/articles/hook_duttaC.html?ca=dgr-lnxw06BestC IBM Best Practices for Programming in C]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html GNU Coding Standards]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html#Names GNU Naming conventions]&lt;br&gt;<br /> More Types<br /> <br /> ==Operators==<br /> <br /> ECMA-334 Operators and punctuators<br /> <br /> C# uses the equals = sign for Assignment<br /> <br /> int myVar = 15; //sets the value of myVar to 15<br /> <br /> ===Mathematical Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |+ ||addition<br /> |-<br /> |- || subtraction<br /> |-<br /> |* || multiplication<br /> |-<br /> |/ || division<br /> |-<br /> |% || modulus remainder Ask Dr.Math What is Modulus?<br /> |}<br /> <br /> ===Increment Decrement Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |++ || increment same as foo = foo + 1<br /> |-<br /> | -- || decrement same as foo = foo - 1<br /> |-<br /> |+= || calculate and reassign addition<br /> |-<br /> | -= || calculate and reassign subtraction<br /> |-<br /> |*= || calculate and reassign multiplication<br /> |-<br /> |/= || calculate and reassign division<br /> |-<br /> |%= || calculate and reassign modulus<br /> |-<br /> |y= x++ || assignment prefix y is assigned to x and then x in incremented<br /> |-<br /> |y= ++x || assignment postfix x is incremented and then assigned to y<br /> |}<br /> <br /> ===Operator Precedence===<br /> Evaluated First<br /> <br /> * ++,--,unary-<br /> * *,/,%<br /> * +,-<br /> <br /> Evaluated Last<br /> <br /> * =,+=,-=,*=,etc<br /> <br /> <br /> {{csharp strings}}<br /> {{csharp string functions}}<br /> <br /> ==Short Assignment==<br /> Short in class Assignment<br /> In class assignment 10-15 mins<br /> Build a c# console app (remember to take a top down aproach start small with something you know maybe start with hello world)<br /> * Declare and initialize two integers<br /> * Display their values using Console.WriteLine<br /> * Declare a third integer and initialize it with the sum of the first two integers<br /> * Output the value of the third integer<br /> <br /> <br /> Top down development with comments [http://iam.colum.edu/oop/classsource/class2/topdown.aspx topdown.aspx]<br /> <br /> Fully implemented Console adding program [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/add.cs add.cs]<br /> <br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> <br /> namespace Hello<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Super Cool Calculatorizer&quot;);<br /> <br /> //Declare two variables<br /> int intOne;<br /> int intTwo;<br /> int intSum;<br /> <br /> //intialize the two variables<br /> intOne = 47;<br /> intTwo = 2;<br /> <br /> //Lets test the values<br /> Console.Write(&quot;Enter a integer: &quot;);<br /> intOne = int.Parse(Console.ReadLine()); //set the value of intOne <br /> //to what was typed in the console<br /> Console.Write(&quot;Enter another integer: &quot;);<br /> intTwo = int.Parse(Console.ReadLine()); //int.Parse attempts to parse a string<br /> //and convert it to an int<br /> <br /> intSum = intOne + intTwo;<br /> <br /> Console.WriteLine(&quot;intTwo + intTwo = &quot; + intSum);<br /> <br /> Console.ReadKey();<br /> <br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> ==Constants==<br /> <br /> Constants are datatypes that will be assigned a value that will be constant thought the executing of the code. You cannot change constants once they have been assigned a value.<br /> syntax<br /> <br /> &lt;csharp&gt;const type identifier = value;&lt;/csharp&gt;<br /> <br /> <br /> example<br /> <br /> &lt;csharp&gt;const int freezingPoint = 32;<br /> const int freezingPointMetric = 0;<br /> const float pi = 3.141592&lt;/csharp&gt;<br /> <br /> <br /> [[OOP Arrays]]<br /> {{csharp arrays}}<br /> <br /> <br /> ==Simple Branching==<br /> <br /> ===if===<br /> syntax<br /> <br /> &lt;csharp&gt;if (expression)<br /> // statement<br /> <br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> else {<br /> // statements<br /> }&lt;/csharp&gt;<br /> <br /> ==HomeWork==<br /> *Learning c#<br /> *Chapter 5, Chapter 6<br /> <br /> <br /> Create a simple text game that asks three questions and sets three variables. There should be a fourth variable that counts the number of correct answers. The program should run in the console and use:<br /> <br /> *Console.WriteLine<br /> *Console.ReadLine<br /> *ints, strings and ifs<br /> <br /> Analysis of Homework Project<br /> *On very structured programs like this one analysis is quite easy<br /> ** Start by identifying the steps<br /> ** Add [http://en.wikipedia.org/wiki/Pseudocode Pseudocode] as c# comments for each step<br /> ** Fill in the real syntax for each step and compile each time to make sure nothing breaks (I like to call this baby steps and I like to use this technique whenever I'm trying to implement something that is completely new to me)<br /> <br /> The pseudocode might look something like<br /> &lt;csharp&gt;using System;<br /> namespace HelloVariables<br /> {<br /> class ThreeQuestions<br /> {<br /> public static void Main()<br /> {<br /> Console.WriteLine(&quot;3 Questions&quot;);<br /> //A simple game that asks three questions and checks the answers. If the question is answered correctly we will award 1 point<br /> <br /> //Declare Variables<br /> <br /> //Ask Question 1<br /> <br /> //Read Answer<br /> <br /> //Check Answer and add 1 to points is correct<br /> <br /> //Repeat with Questions 2 and 3<br /> <br /> //Display Percent Correct<br /> <br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> ==Video==<br /> &lt;html&gt;<br /> &lt;script type='text/javascript' src='http://iam.colum.edu/videotutorials/mediaplayer-5.2/swfobject.js'&gt;&lt;/script&gt; <br /> &lt;div id='mediaspace2'&gt;This text will be replaced&lt;/div&gt; <br /> &lt;script type='text/javascript'&gt;<br /> var so = new SWFObject('http://iam.colum.edu/videotutorials/mediaplayer-5.2/player.swf','mpl','800','600','9');so.addParam('allowfullscreen','true')<br /> ;so.addParam('allowscriptaccess','always');<br /> so.addParam('wmode','opaque');<br /> so.addVariable('file','http://iam.colum.edu/screenz/FA13/OOP_Week_2/OOP_Week_2.mp4');<br /> so.addVariable('autostart','false');<br /> so.write('mediaspace2');<br /> <br /> &lt;/script&gt;<br /> <br /> &lt;/html&gt;<br /> <br /> Visit<br /> <br /> http://iam.colum.edu/screenz/FA13/OOP_Week_2/<br /> <br /> and select OOP_Week_2.html<br /> <br /> for this weeks class video</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class2&diff=21734 OOP Class2 2013-09-16T17:52:23Z <p>Cameron.Cintron: /* Video */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> ==Posting home work and website==<br /> <br /> =C# fundamentals=<br /> <br /> Questions from week 1 reading.<br /> discussion<br /> <br /> Some pages comparing c# to other languages<br /> <br /> A Comparative Overview of C# http://genamics.com/developer/csharp_comparative.htm<br /> <br /> C# and Java: Comparing Programming Languages http://msdn.microsoft.com/en-us/library/ms836794.aspx<br /> <br /> ==Terms==<br /> <br /> CLR<br /> :Common Language Runtime<br /> namespace<br /> :organizing classes with hierarchy <br /> keyword<br /> :reserved system word<br /> MSIL<br /> :MicroSoft Intermediary Language<br /> JIT<br /> :Just In Time compilation @ first run<br /> <br /> ==Everything is an Object==<br /> In c# everything is an object. And all objects inherit from the object class.<br /> <br /> [http://quickstarts.asp.net/QuickStartv20/util/classbrowser.aspx See object in the classbrowser]<br /> <br /> Since all objects inherit from the object class they all have some the basic functionality like a method called ToString();<br /> <br /> [http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class2/FromMono See the source for object.cs from mono] <br /> <br /> <br /> ==Basic Data Types==<br /> <br /> C# is a strongly typed language. This means every object in C# must be declared to be of a specific type. All of c# basic varible type inherit from [http://msdn2.microsoft.com/en-us/library/system.object.aspx System.Object]<br /> <br /> {{.NET Data Types}}<br /> <br /> Variables must be declared with an identifier and then initialized.<br /> <br /> ===Declaration===<br /> <br /> Declaration sets aside a named section of memory the is the proper size to hold the declared type. At this point the variable contains nothing.<br /> <br /> &lt;csharp&gt;// declare a variable<br /> int firstInt; //declares a vaiable of type int<br /> string myString; //declares a vaiable of type string&lt;/csharp&gt;<br /> <br /> ===Initialization===<br /> <br /> Initialization actually sets the variables value<br /> <br /> &lt;csharp&gt;// initialize the variable<br /> firstInt = 1;<br /> myString = &quot;Hello!&quot;;&lt;/csharp&gt;<br /> <br /> Initialization uses the assignment operator to set the value of a variable<br /> <br /> ===Assignment===<br /> The Assignment '''operator''' in c# is the '=' sign. You can assign variables like this...<br /> <br /> ==Assignment==<br /> The Assignment operator in c# is the '=' sign. You can assign variables like this...<br /> We'll learn more about operators later.<br /> <br /> other ways to do it<br /> <br /> &lt;csharp&gt;// declare some variables<br /> int secondInt, thirdInt, fourthInt;<br /> secondInt = 2;<br /> thirdInt = 3;<br /> fourthInt = 4;<br /> <br /> //declare and initialize variables in one line<br /> int myNegativeInt = -2147483648;&lt;/csharp&gt;<br /> <br /> In c# variables cannot be used unil they are initalized.<br /> For example<br /> <br /> &lt;csharp&gt;int UsedBeforeInit;<br /> Console.WriteLine(UsedBeforeInit);&lt;/csharp&gt;<br /> <br /> will produce<br /> <br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> <br /> ==Compiler Errors==<br /> error<br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> file Line .Net Framework error # and description<br /> <br /> <br /> <br /> [[Csharp warning CS0168: The variable 'NeverUsed' is declared but never used]]<br /> <br /> <br /> <br /> <br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit.cs UsedBeforeInit.cs] - example of misused variable&lt;br /&gt;<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit_Fixed.cs UsedBeforeInit_Fixed.cs] - all beter now source&lt;br /&gt;<br /> <br /> More examples of built in types<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/csharpfundamentals/1x1.cs 1x1.cs] C# intrinsic types from Learn-C-Sharp.<br /> variable.aspx - example from book aspx page View Source<br /> variable2.aspx = example from book errors View Source<br /> <br /> ==Variable Names==<br /> <br /> Variable should be named with meaningful names.<br /> <br /> for exmaple <br /> :z = x * y;<br /> <br /> does not convey any meaning<br /> <br /> but<br /> :distance = speed * time;<br /> <br /> does convey meaning.<br /> If varibales are named properly it can make your code mush easier to read.<br /> <br /> ==Naming conventions==<br /> Name variables intelligently.&lt;br&gt;<br /> Name variables with names that have meaning.&lt;br&gt;<br /> <br /> ===Hungarian Notation===<br /> Hungarian notation id a popular notation system used be many C, C++ and VB programmers. It was originally devised in Charles Simonyi's doctoral thesis, &quot;Meta-Programming: A Software Production Method.&quot; Hungarian notation specifies that a prefix be added to each variable that indicated that variables type. It also specifies sometimes adding a suffice to clarify variables meaning. In the early 1980's Microsoft adopted this notation system.<br /> <br /> <br /> ie... intHitCounter, intHitsPerMonthMax <br /> <br /> [http://msdn.microsoft.com/en-us/library/aa260976(VS.60).aspx Hungarian Notation - Charles Simonyi Microsoft]<br /> <br /> http://msdn.microsoft.com/en-us/library/ms229045.aspx<br /> <br /> '''PascalNotation'''<br /> Capitalize first Letter and then the first letter on each word. &lt;br&gt;<br /> ie... PascalNotation, IntVarName<br /> <br /> Use on method names method names.<br /> <br /> '''camelNotation'''<br /> Lower case first letter and then capitalize the first letter of each word&lt;br&gt;<br /> ie... camelNotation, intVarName<br /> <br /> use for variable names<br /> <br /> Other Coding Techniques and practices&lt;br&gt;<br /> [http://msdn.microsoft.com/en-us/library/ms229002.aspx .NET Framework Developer's Guide<br /> Guidelines for Names]&lt;br&gt;<br /> [http://www-106.ibm.com/developerworks/eserver/articles/hook_duttaC.html?ca=dgr-lnxw06BestC IBM Best Practices for Programming in C]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html GNU Coding Standards]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html#Names GNU Naming conventions]&lt;br&gt;<br /> More Types<br /> <br /> ==Operators==<br /> <br /> ECMA-334 Operators and punctuators<br /> <br /> C# uses the equals = sign for Assignment<br /> <br /> int myVar = 15; //sets the value of myVar to 15<br /> <br /> ===Mathematical Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |+ ||addition<br /> |-<br /> |- || subtraction<br /> |-<br /> |* || multiplication<br /> |-<br /> |/ || division<br /> |-<br /> |% || modulus remainder Ask Dr.Math What is Modulus?<br /> |}<br /> <br /> ===Increment Decrement Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |++ || increment same as foo = foo + 1<br /> |-<br /> | -- || decrement same as foo = foo - 1<br /> |-<br /> |+= || calculate and reassign addition<br /> |-<br /> | -= || calculate and reassign subtraction<br /> |-<br /> |*= || calculate and reassign multiplication<br /> |-<br /> |/= || calculate and reassign division<br /> |-<br /> |%= || calculate and reassign modulus<br /> |-<br /> |y= x++ || assignment prefix y is assigned to x and then x in incremented<br /> |-<br /> |y= ++x || assignment postfix x is incremented and then assigned to y<br /> |}<br /> <br /> ===Operator Precedence===<br /> Evaluated First<br /> <br /> * ++,--,unary-<br /> * *,/,%<br /> * +,-<br /> <br /> Evaluated Last<br /> <br /> * =,+=,-=,*=,etc<br /> <br /> <br /> {{csharp strings}}<br /> {{csharp string functions}}<br /> <br /> ==Short Assignment==<br /> Short in class Assignment<br /> In class assignment 10-15 mins<br /> Build a c# console app (remember to take a top down aproach start small with something you know maybe start with hello world)<br /> * Declare and initialize two integers<br /> * Display their values using Console.WriteLine<br /> * Declare a third integer and initialize it with the sum of the first two integers<br /> * Output the value of the third integer<br /> <br /> <br /> Top down development with comments [http://iam.colum.edu/oop/classsource/class2/topdown.aspx topdown.aspx]<br /> <br /> Fully implemented Console adding program [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/add.cs add.cs]<br /> <br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> <br /> namespace Hello<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Super Cool Calculatorizer&quot;);<br /> <br /> //Declare two variables<br /> int intOne;<br /> int intTwo;<br /> int intSum;<br /> <br /> //intialize the two variables<br /> intOne = 47;<br /> intTwo = 2;<br /> <br /> //Lets test the values<br /> Console.Write(&quot;Enter a integer: &quot;);<br /> intOne = int.Parse(Console.ReadLine()); //set the value of intOne <br /> //to what was typed in the console<br /> Console.Write(&quot;Enter another integer: &quot;);<br /> intTwo = int.Parse(Console.ReadLine()); //int.Parse attempts to parse a string<br /> //and convert it to an int<br /> <br /> intSum = intOne + intTwo;<br /> <br /> Console.WriteLine(&quot;intTwo + intTwo = &quot; + intSum);<br /> <br /> Console.ReadKey();<br /> <br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> ==Constants==<br /> <br /> Constants are datatypes that will be assigned a value that will be constant thought the executing of the code. You cannot change constants once they have been assigned a value.<br /> syntax<br /> <br /> &lt;csharp&gt;const type identifier = value;&lt;/csharp&gt;<br /> <br /> <br /> example<br /> <br /> &lt;csharp&gt;const int freezingPoint = 32;<br /> const int freezingPointMetric = 0;<br /> const float pi = 3.141592&lt;/csharp&gt;<br /> <br /> <br /> [[OOP Arrays]]<br /> {{csharp arrays}}<br /> <br /> <br /> ==Simple Branching==<br /> <br /> ===if===<br /> syntax<br /> <br /> &lt;csharp&gt;if (expression)<br /> // statement<br /> <br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> else {<br /> // statements<br /> }&lt;/csharp&gt;<br /> <br /> ==HomeWork==<br /> *Learning c#<br /> *Chapter 5, Chapter 6<br /> <br /> <br /> Create a simple text game that asks three questions and sets three variables. There should be a fourth variable that counts the number of correct answers. The program should run in the console and use:<br /> <br /> *Console.WriteLine<br /> *Console.ReadLine<br /> *ints, strings and ifs<br /> <br /> Analysis of Homework Project<br /> *On very structured programs like this one analysis is quite easy<br /> ** Start by identifying the steps<br /> ** Add [http://en.wikipedia.org/wiki/Pseudocode Pseudocode] as c# comments for each step<br /> ** Fill in the real syntax for each step and compile each time to make sure nothing breaks (I like to call this baby steps and I like to use this technique whenever I'm trying to implement something that is completely new to me)<br /> <br /> The pseudocode might look something like<br /> &lt;csharp&gt;using System;<br /> namespace HelloVariables<br /> {<br /> class ThreeQuestions<br /> {<br /> public static void Main()<br /> {<br /> Console.WriteLine(&quot;3 Questions&quot;);<br /> //A simple game that asks three questions and checks the answers. If the question is answered correctly we will award 1 point<br /> <br /> //Declare Variables<br /> <br /> //Ask Question 1<br /> <br /> //Read Answer<br /> <br /> //Check Answer and add 1 to points is correct<br /> <br /> //Repeat with Questions 2 and 3<br /> <br /> //Display Percent Correct<br /> <br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> ==Video==<br /> &lt;html&gt;<br /> &lt;script type='text/javascript' src='http://iam.colum.edu/videotutorials/mediaplayer-5.2/swfobject.js'&gt;&lt;/script&gt; <br /> &lt;div id='mediaspace2'&gt;This text will be replaced&lt;/div&gt; <br /> &lt;script type='text/javascript'&gt;<br /> var so = new SWFObject('http://iam.colum.edu/videotutorials/mediaplayer-5.2/player.swf','mpl','800','600','9');so.addParam('allowfullscreen','true')<br /> ;so.addParam('allowscriptaccess','always');<br /> so.addParam('wmode','opaque');<br /> so.addVariable('file','http://iam.colum.edu/screenz/FA13/OOP_Week_2.mp4');<br /> so.addVariable('autostart','false');<br /> so.write('mediaspace2');<br /> <br /> &lt;/script&gt;<br /> <br /> &lt;/html&gt;<br /> <br /> Visit<br /> <br /> http://iam.colum.edu/screenz/FA13/OOP_Week_2/<br /> <br /> and select OOP_Week_2.html<br /> <br /> for this weeks class video</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class2&diff=21733 OOP Class2 2013-09-16T17:38:30Z <p>Cameron.Cintron: /* Video */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> ==Posting home work and website==<br /> <br /> =C# fundamentals=<br /> <br /> Questions from week 1 reading.<br /> discussion<br /> <br /> Some pages comparing c# to other languages<br /> <br /> A Comparative Overview of C# http://genamics.com/developer/csharp_comparative.htm<br /> <br /> C# and Java: Comparing Programming Languages http://msdn.microsoft.com/en-us/library/ms836794.aspx<br /> <br /> ==Terms==<br /> <br /> CLR<br /> :Common Language Runtime<br /> namespace<br /> :organizing classes with hierarchy <br /> keyword<br /> :reserved system word<br /> MSIL<br /> :MicroSoft Intermediary Language<br /> JIT<br /> :Just In Time compilation @ first run<br /> <br /> ==Everything is an Object==<br /> In c# everything is an object. And all objects inherit from the object class.<br /> <br /> [http://quickstarts.asp.net/QuickStartv20/util/classbrowser.aspx See object in the classbrowser]<br /> <br /> Since all objects inherit from the object class they all have some the basic functionality like a method called ToString();<br /> <br /> [http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class2/FromMono See the source for object.cs from mono] <br /> <br /> <br /> ==Basic Data Types==<br /> <br /> C# is a strongly typed language. This means every object in C# must be declared to be of a specific type. All of c# basic varible type inherit from [http://msdn2.microsoft.com/en-us/library/system.object.aspx System.Object]<br /> <br /> {{.NET Data Types}}<br /> <br /> Variables must be declared with an identifier and then initialized.<br /> <br /> ===Declaration===<br /> <br /> Declaration sets aside a named section of memory the is the proper size to hold the declared type. At this point the variable contains nothing.<br /> <br /> &lt;csharp&gt;// declare a variable<br /> int firstInt; //declares a vaiable of type int<br /> string myString; //declares a vaiable of type string&lt;/csharp&gt;<br /> <br /> ===Initialization===<br /> <br /> Initialization actually sets the variables value<br /> <br /> &lt;csharp&gt;// initialize the variable<br /> firstInt = 1;<br /> myString = &quot;Hello!&quot;;&lt;/csharp&gt;<br /> <br /> Initialization uses the assignment operator to set the value of a variable<br /> <br /> ===Assignment===<br /> The Assignment '''operator''' in c# is the '=' sign. You can assign variables like this...<br /> <br /> ==Assignment==<br /> The Assignment operator in c# is the '=' sign. You can assign variables like this...<br /> We'll learn more about operators later.<br /> <br /> other ways to do it<br /> <br /> &lt;csharp&gt;// declare some variables<br /> int secondInt, thirdInt, fourthInt;<br /> secondInt = 2;<br /> thirdInt = 3;<br /> fourthInt = 4;<br /> <br /> //declare and initialize variables in one line<br /> int myNegativeInt = -2147483648;&lt;/csharp&gt;<br /> <br /> In c# variables cannot be used unil they are initalized.<br /> For example<br /> <br /> &lt;csharp&gt;int UsedBeforeInit;<br /> Console.WriteLine(UsedBeforeInit);&lt;/csharp&gt;<br /> <br /> will produce<br /> <br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> <br /> ==Compiler Errors==<br /> error<br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> file Line .Net Framework error # and description<br /> <br /> <br /> <br /> [[Csharp warning CS0168: The variable 'NeverUsed' is declared but never used]]<br /> <br /> <br /> <br /> <br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit.cs UsedBeforeInit.cs] - example of misused variable&lt;br /&gt;<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit_Fixed.cs UsedBeforeInit_Fixed.cs] - all beter now source&lt;br /&gt;<br /> <br /> More examples of built in types<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/csharpfundamentals/1x1.cs 1x1.cs] C# intrinsic types from Learn-C-Sharp.<br /> variable.aspx - example from book aspx page View Source<br /> variable2.aspx = example from book errors View Source<br /> <br /> ==Variable Names==<br /> <br /> Variable should be named with meaningful names.<br /> <br /> for exmaple <br /> :z = x * y;<br /> <br /> does not convey any meaning<br /> <br /> but<br /> :distance = speed * time;<br /> <br /> does convey meaning.<br /> If varibales are named properly it can make your code mush easier to read.<br /> <br /> ==Naming conventions==<br /> Name variables intelligently.&lt;br&gt;<br /> Name variables with names that have meaning.&lt;br&gt;<br /> <br /> ===Hungarian Notation===<br /> Hungarian notation id a popular notation system used be many C, C++ and VB programmers. It was originally devised in Charles Simonyi's doctoral thesis, &quot;Meta-Programming: A Software Production Method.&quot; Hungarian notation specifies that a prefix be added to each variable that indicated that variables type. It also specifies sometimes adding a suffice to clarify variables meaning. In the early 1980's Microsoft adopted this notation system.<br /> <br /> <br /> ie... intHitCounter, intHitsPerMonthMax <br /> <br /> [http://msdn.microsoft.com/en-us/library/aa260976(VS.60).aspx Hungarian Notation - Charles Simonyi Microsoft]<br /> <br /> http://msdn.microsoft.com/en-us/library/ms229045.aspx<br /> <br /> '''PascalNotation'''<br /> Capitalize first Letter and then the first letter on each word. &lt;br&gt;<br /> ie... PascalNotation, IntVarName<br /> <br /> Use on method names method names.<br /> <br /> '''camelNotation'''<br /> Lower case first letter and then capitalize the first letter of each word&lt;br&gt;<br /> ie... camelNotation, intVarName<br /> <br /> use for variable names<br /> <br /> Other Coding Techniques and practices&lt;br&gt;<br /> [http://msdn.microsoft.com/en-us/library/ms229002.aspx .NET Framework Developer's Guide<br /> Guidelines for Names]&lt;br&gt;<br /> [http://www-106.ibm.com/developerworks/eserver/articles/hook_duttaC.html?ca=dgr-lnxw06BestC IBM Best Practices for Programming in C]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html GNU Coding Standards]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html#Names GNU Naming conventions]&lt;br&gt;<br /> More Types<br /> <br /> ==Operators==<br /> <br /> ECMA-334 Operators and punctuators<br /> <br /> C# uses the equals = sign for Assignment<br /> <br /> int myVar = 15; //sets the value of myVar to 15<br /> <br /> ===Mathematical Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |+ ||addition<br /> |-<br /> |- || subtraction<br /> |-<br /> |* || multiplication<br /> |-<br /> |/ || division<br /> |-<br /> |% || modulus remainder Ask Dr.Math What is Modulus?<br /> |}<br /> <br /> ===Increment Decrement Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |++ || increment same as foo = foo + 1<br /> |-<br /> | -- || decrement same as foo = foo - 1<br /> |-<br /> |+= || calculate and reassign addition<br /> |-<br /> | -= || calculate and reassign subtraction<br /> |-<br /> |*= || calculate and reassign multiplication<br /> |-<br /> |/= || calculate and reassign division<br /> |-<br /> |%= || calculate and reassign modulus<br /> |-<br /> |y= x++ || assignment prefix y is assigned to x and then x in incremented<br /> |-<br /> |y= ++x || assignment postfix x is incremented and then assigned to y<br /> |}<br /> <br /> ===Operator Precedence===<br /> Evaluated First<br /> <br /> * ++,--,unary-<br /> * *,/,%<br /> * +,-<br /> <br /> Evaluated Last<br /> <br /> * =,+=,-=,*=,etc<br /> <br /> <br /> {{csharp strings}}<br /> {{csharp string functions}}<br /> <br /> ==Short Assignment==<br /> Short in class Assignment<br /> In class assignment 10-15 mins<br /> Build a c# console app (remember to take a top down aproach start small with something you know maybe start with hello world)<br /> * Declare and initialize two integers<br /> * Display their values using Console.WriteLine<br /> * Declare a third integer and initialize it with the sum of the first two integers<br /> * Output the value of the third integer<br /> <br /> <br /> Top down development with comments [http://iam.colum.edu/oop/classsource/class2/topdown.aspx topdown.aspx]<br /> <br /> Fully implemented Console adding program [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/add.cs add.cs]<br /> <br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> <br /> namespace Hello<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Super Cool Calculatorizer&quot;);<br /> <br /> //Declare two variables<br /> int intOne;<br /> int intTwo;<br /> int intSum;<br /> <br /> //intialize the two variables<br /> intOne = 47;<br /> intTwo = 2;<br /> <br /> //Lets test the values<br /> Console.Write(&quot;Enter a integer: &quot;);<br /> intOne = int.Parse(Console.ReadLine()); //set the value of intOne <br /> //to what was typed in the console<br /> Console.Write(&quot;Enter another integer: &quot;);<br /> intTwo = int.Parse(Console.ReadLine()); //int.Parse attempts to parse a string<br /> //and convert it to an int<br /> <br /> intSum = intOne + intTwo;<br /> <br /> Console.WriteLine(&quot;intTwo + intTwo = &quot; + intSum);<br /> <br /> Console.ReadKey();<br /> <br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> ==Constants==<br /> <br /> Constants are datatypes that will be assigned a value that will be constant thought the executing of the code. You cannot change constants once they have been assigned a value.<br /> syntax<br /> <br /> &lt;csharp&gt;const type identifier = value;&lt;/csharp&gt;<br /> <br /> <br /> example<br /> <br /> &lt;csharp&gt;const int freezingPoint = 32;<br /> const int freezingPointMetric = 0;<br /> const float pi = 3.141592&lt;/csharp&gt;<br /> <br /> <br /> [[OOP Arrays]]<br /> {{csharp arrays}}<br /> <br /> <br /> ==Simple Branching==<br /> <br /> ===if===<br /> syntax<br /> <br /> &lt;csharp&gt;if (expression)<br /> // statement<br /> <br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> else {<br /> // statements<br /> }&lt;/csharp&gt;<br /> <br /> ==HomeWork==<br /> *Learning c#<br /> *Chapter 5, Chapter 6<br /> <br /> <br /> Create a simple text game that asks three questions and sets three variables. There should be a fourth variable that counts the number of correct answers. The program should run in the console and use:<br /> <br /> *Console.WriteLine<br /> *Console.ReadLine<br /> *ints, strings and ifs<br /> <br /> Analysis of Homework Project<br /> *On very structured programs like this one analysis is quite easy<br /> ** Start by identifying the steps<br /> ** Add [http://en.wikipedia.org/wiki/Pseudocode Pseudocode] as c# comments for each step<br /> ** Fill in the real syntax for each step and compile each time to make sure nothing breaks (I like to call this baby steps and I like to use this technique whenever I'm trying to implement something that is completely new to me)<br /> <br /> The pseudocode might look something like<br /> &lt;csharp&gt;using System;<br /> namespace HelloVariables<br /> {<br /> class ThreeQuestions<br /> {<br /> public static void Main()<br /> {<br /> Console.WriteLine(&quot;3 Questions&quot;);<br /> //A simple game that asks three questions and checks the answers. If the question is answered correctly we will award 1 point<br /> <br /> //Declare Variables<br /> <br /> //Ask Question 1<br /> <br /> //Read Answer<br /> <br /> //Check Answer and add 1 to points is correct<br /> <br /> //Repeat with Questions 2 and 3<br /> <br /> //Display Percent Correct<br /> <br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> ==Video==<br /> &lt;html&gt;<br /> &lt;script type='text/javascript' src='http://iam.colum.edu/videotutorials/mediaplayer-5.2/swfobject.js'&gt;&lt;/script&gt; <br /> &lt;div id='mediaspace2'&gt;This text will be replaced&lt;/div&gt; <br /> &lt;script type='text/javascript'&gt;<br /> var so = new SWFObject('http://iam.colum.edu/videotutorials/mediaplayer-5.2/player.swf','mpl','800','600','9');so.addParam('allowfullscreen','true')<br /> ;so.addParam('allowscriptaccess','always');<br /> so.addParam('wmode','opaque');<br /> so.addVariable('file','http://iam.colum.edu/screenz/FA13/OOP_Week_2.mp4');<br /> so.addVariable('autostart','false');<br /> so.write('mediaspace2');<br /> <br /> &lt;/script&gt;<br /> <br /> &lt;/html&gt;<br /> <br /> Visit<br /> http://iam.colum.edu/screenz/FA13/OOP_Week_2.mp4<br /> http://iam.colum.edu/screenz/FA13/OOP_Week_2/<br /> <br /> and select OOP_Week_2.html<br /> <br /> for this weeks class video</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class2&diff=21732 OOP Class2 2013-09-16T17:38:11Z <p>Cameron.Cintron: /* Video */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> ==Posting home work and website==<br /> <br /> =C# fundamentals=<br /> <br /> Questions from week 1 reading.<br /> discussion<br /> <br /> Some pages comparing c# to other languages<br /> <br /> A Comparative Overview of C# http://genamics.com/developer/csharp_comparative.htm<br /> <br /> C# and Java: Comparing Programming Languages http://msdn.microsoft.com/en-us/library/ms836794.aspx<br /> <br /> ==Terms==<br /> <br /> CLR<br /> :Common Language Runtime<br /> namespace<br /> :organizing classes with hierarchy <br /> keyword<br /> :reserved system word<br /> MSIL<br /> :MicroSoft Intermediary Language<br /> JIT<br /> :Just In Time compilation @ first run<br /> <br /> ==Everything is an Object==<br /> In c# everything is an object. And all objects inherit from the object class.<br /> <br /> [http://quickstarts.asp.net/QuickStartv20/util/classbrowser.aspx See object in the classbrowser]<br /> <br /> Since all objects inherit from the object class they all have some the basic functionality like a method called ToString();<br /> <br /> [http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class2/FromMono See the source for object.cs from mono] <br /> <br /> <br /> ==Basic Data Types==<br /> <br /> C# is a strongly typed language. This means every object in C# must be declared to be of a specific type. All of c# basic varible type inherit from [http://msdn2.microsoft.com/en-us/library/system.object.aspx System.Object]<br /> <br /> {{.NET Data Types}}<br /> <br /> Variables must be declared with an identifier and then initialized.<br /> <br /> ===Declaration===<br /> <br /> Declaration sets aside a named section of memory the is the proper size to hold the declared type. At this point the variable contains nothing.<br /> <br /> &lt;csharp&gt;// declare a variable<br /> int firstInt; //declares a vaiable of type int<br /> string myString; //declares a vaiable of type string&lt;/csharp&gt;<br /> <br /> ===Initialization===<br /> <br /> Initialization actually sets the variables value<br /> <br /> &lt;csharp&gt;// initialize the variable<br /> firstInt = 1;<br /> myString = &quot;Hello!&quot;;&lt;/csharp&gt;<br /> <br /> Initialization uses the assignment operator to set the value of a variable<br /> <br /> ===Assignment===<br /> The Assignment '''operator''' in c# is the '=' sign. You can assign variables like this...<br /> <br /> ==Assignment==<br /> The Assignment operator in c# is the '=' sign. You can assign variables like this...<br /> We'll learn more about operators later.<br /> <br /> other ways to do it<br /> <br /> &lt;csharp&gt;// declare some variables<br /> int secondInt, thirdInt, fourthInt;<br /> secondInt = 2;<br /> thirdInt = 3;<br /> fourthInt = 4;<br /> <br /> //declare and initialize variables in one line<br /> int myNegativeInt = -2147483648;&lt;/csharp&gt;<br /> <br /> In c# variables cannot be used unil they are initalized.<br /> For example<br /> <br /> &lt;csharp&gt;int UsedBeforeInit;<br /> Console.WriteLine(UsedBeforeInit);&lt;/csharp&gt;<br /> <br /> will produce<br /> <br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> <br /> ==Compiler Errors==<br /> error<br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> file Line .Net Framework error # and description<br /> <br /> <br /> <br /> [[Csharp warning CS0168: The variable 'NeverUsed' is declared but never used]]<br /> <br /> <br /> <br /> <br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit.cs UsedBeforeInit.cs] - example of misused variable&lt;br /&gt;<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit_Fixed.cs UsedBeforeInit_Fixed.cs] - all beter now source&lt;br /&gt;<br /> <br /> More examples of built in types<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/csharpfundamentals/1x1.cs 1x1.cs] C# intrinsic types from Learn-C-Sharp.<br /> variable.aspx - example from book aspx page View Source<br /> variable2.aspx = example from book errors View Source<br /> <br /> ==Variable Names==<br /> <br /> Variable should be named with meaningful names.<br /> <br /> for exmaple <br /> :z = x * y;<br /> <br /> does not convey any meaning<br /> <br /> but<br /> :distance = speed * time;<br /> <br /> does convey meaning.<br /> If varibales are named properly it can make your code mush easier to read.<br /> <br /> ==Naming conventions==<br /> Name variables intelligently.&lt;br&gt;<br /> Name variables with names that have meaning.&lt;br&gt;<br /> <br /> ===Hungarian Notation===<br /> Hungarian notation id a popular notation system used be many C, C++ and VB programmers. It was originally devised in Charles Simonyi's doctoral thesis, &quot;Meta-Programming: A Software Production Method.&quot; Hungarian notation specifies that a prefix be added to each variable that indicated that variables type. It also specifies sometimes adding a suffice to clarify variables meaning. In the early 1980's Microsoft adopted this notation system.<br /> <br /> <br /> ie... intHitCounter, intHitsPerMonthMax <br /> <br /> [http://msdn.microsoft.com/en-us/library/aa260976(VS.60).aspx Hungarian Notation - Charles Simonyi Microsoft]<br /> <br /> http://msdn.microsoft.com/en-us/library/ms229045.aspx<br /> <br /> '''PascalNotation'''<br /> Capitalize first Letter and then the first letter on each word. &lt;br&gt;<br /> ie... PascalNotation, IntVarName<br /> <br /> Use on method names method names.<br /> <br /> '''camelNotation'''<br /> Lower case first letter and then capitalize the first letter of each word&lt;br&gt;<br /> ie... camelNotation, intVarName<br /> <br /> use for variable names<br /> <br /> Other Coding Techniques and practices&lt;br&gt;<br /> [http://msdn.microsoft.com/en-us/library/ms229002.aspx .NET Framework Developer's Guide<br /> Guidelines for Names]&lt;br&gt;<br /> [http://www-106.ibm.com/developerworks/eserver/articles/hook_duttaC.html?ca=dgr-lnxw06BestC IBM Best Practices for Programming in C]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html GNU Coding Standards]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html#Names GNU Naming conventions]&lt;br&gt;<br /> More Types<br /> <br /> ==Operators==<br /> <br /> ECMA-334 Operators and punctuators<br /> <br /> C# uses the equals = sign for Assignment<br /> <br /> int myVar = 15; //sets the value of myVar to 15<br /> <br /> ===Mathematical Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |+ ||addition<br /> |-<br /> |- || subtraction<br /> |-<br /> |* || multiplication<br /> |-<br /> |/ || division<br /> |-<br /> |% || modulus remainder Ask Dr.Math What is Modulus?<br /> |}<br /> <br /> ===Increment Decrement Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |++ || increment same as foo = foo + 1<br /> |-<br /> | -- || decrement same as foo = foo - 1<br /> |-<br /> |+= || calculate and reassign addition<br /> |-<br /> | -= || calculate and reassign subtraction<br /> |-<br /> |*= || calculate and reassign multiplication<br /> |-<br /> |/= || calculate and reassign division<br /> |-<br /> |%= || calculate and reassign modulus<br /> |-<br /> |y= x++ || assignment prefix y is assigned to x and then x in incremented<br /> |-<br /> |y= ++x || assignment postfix x is incremented and then assigned to y<br /> |}<br /> <br /> ===Operator Precedence===<br /> Evaluated First<br /> <br /> * ++,--,unary-<br /> * *,/,%<br /> * +,-<br /> <br /> Evaluated Last<br /> <br /> * =,+=,-=,*=,etc<br /> <br /> <br /> {{csharp strings}}<br /> {{csharp string functions}}<br /> <br /> ==Short Assignment==<br /> Short in class Assignment<br /> In class assignment 10-15 mins<br /> Build a c# console app (remember to take a top down aproach start small with something you know maybe start with hello world)<br /> * Declare and initialize two integers<br /> * Display their values using Console.WriteLine<br /> * Declare a third integer and initialize it with the sum of the first two integers<br /> * Output the value of the third integer<br /> <br /> <br /> Top down development with comments [http://iam.colum.edu/oop/classsource/class2/topdown.aspx topdown.aspx]<br /> <br /> Fully implemented Console adding program [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/add.cs add.cs]<br /> <br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> <br /> namespace Hello<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Super Cool Calculatorizer&quot;);<br /> <br /> //Declare two variables<br /> int intOne;<br /> int intTwo;<br /> int intSum;<br /> <br /> //intialize the two variables<br /> intOne = 47;<br /> intTwo = 2;<br /> <br /> //Lets test the values<br /> Console.Write(&quot;Enter a integer: &quot;);<br /> intOne = int.Parse(Console.ReadLine()); //set the value of intOne <br /> //to what was typed in the console<br /> Console.Write(&quot;Enter another integer: &quot;);<br /> intTwo = int.Parse(Console.ReadLine()); //int.Parse attempts to parse a string<br /> //and convert it to an int<br /> <br /> intSum = intOne + intTwo;<br /> <br /> Console.WriteLine(&quot;intTwo + intTwo = &quot; + intSum);<br /> <br /> Console.ReadKey();<br /> <br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> ==Constants==<br /> <br /> Constants are datatypes that will be assigned a value that will be constant thought the executing of the code. You cannot change constants once they have been assigned a value.<br /> syntax<br /> <br /> &lt;csharp&gt;const type identifier = value;&lt;/csharp&gt;<br /> <br /> <br /> example<br /> <br /> &lt;csharp&gt;const int freezingPoint = 32;<br /> const int freezingPointMetric = 0;<br /> const float pi = 3.141592&lt;/csharp&gt;<br /> <br /> <br /> [[OOP Arrays]]<br /> {{csharp arrays}}<br /> <br /> <br /> ==Simple Branching==<br /> <br /> ===if===<br /> syntax<br /> <br /> &lt;csharp&gt;if (expression)<br /> // statement<br /> <br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> else {<br /> // statements<br /> }&lt;/csharp&gt;<br /> <br /> ==HomeWork==<br /> *Learning c#<br /> *Chapter 5, Chapter 6<br /> <br /> <br /> Create a simple text game that asks three questions and sets three variables. There should be a fourth variable that counts the number of correct answers. The program should run in the console and use:<br /> <br /> *Console.WriteLine<br /> *Console.ReadLine<br /> *ints, strings and ifs<br /> <br /> Analysis of Homework Project<br /> *On very structured programs like this one analysis is quite easy<br /> ** Start by identifying the steps<br /> ** Add [http://en.wikipedia.org/wiki/Pseudocode Pseudocode] as c# comments for each step<br /> ** Fill in the real syntax for each step and compile each time to make sure nothing breaks (I like to call this baby steps and I like to use this technique whenever I'm trying to implement something that is completely new to me)<br /> <br /> The pseudocode might look something like<br /> &lt;csharp&gt;using System;<br /> namespace HelloVariables<br /> {<br /> class ThreeQuestions<br /> {<br /> public static void Main()<br /> {<br /> Console.WriteLine(&quot;3 Questions&quot;);<br /> //A simple game that asks three questions and checks the answers. If the question is answered correctly we will award 1 point<br /> <br /> //Declare Variables<br /> <br /> //Ask Question 1<br /> <br /> //Read Answer<br /> <br /> //Check Answer and add 1 to points is correct<br /> <br /> //Repeat with Questions 2 and 3<br /> <br /> //Display Percent Correct<br /> <br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> ==Video==<br /> &lt;html&gt;<br /> &lt;script type='text/javascript' src='http://iam.colum.edu/videotutorials/mediaplayer-5.2/swfobject.js'&gt;&lt;/script&gt; <br /> &lt;div id='mediaspace2'&gt;This text will be replaced&lt;/div&gt; <br /> &lt;script type='text/javascript'&gt;<br /> var so = new SWFObject('http://iam.colum.edu/videotutorials/mediaplayer-5.2/player.swf','mpl','800','600','9');so.addParam('allowfullscreen','true')<br /> ;so.addParam('allowscriptaccess','always');<br /> so.addParam('wmode','opaque');<br /> so.addVariable('file','http://iam.colum.edu/videotutorials/MACFTPS.mp4');<br /> so.addVariable('autostart','false');<br /> so.write('mediaspace2');<br /> <br /> &lt;/script&gt;<br /> <br /> &lt;/html&gt;<br /> <br /> Visit<br /> http://iam.colum.edu/screenz/FA13/OOP_Week_2.mp4<br /> http://iam.colum.edu/screenz/FA13/OOP_Week_2/<br /> <br /> and select OOP_Week_2.html<br /> <br /> for this weeks class video</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class2&diff=21731 OOP Class2 2013-09-16T17:35:22Z <p>Cameron.Cintron: /* Video */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> ==Posting home work and website==<br /> <br /> =C# fundamentals=<br /> <br /> Questions from week 1 reading.<br /> discussion<br /> <br /> Some pages comparing c# to other languages<br /> <br /> A Comparative Overview of C# http://genamics.com/developer/csharp_comparative.htm<br /> <br /> C# and Java: Comparing Programming Languages http://msdn.microsoft.com/en-us/library/ms836794.aspx<br /> <br /> ==Terms==<br /> <br /> CLR<br /> :Common Language Runtime<br /> namespace<br /> :organizing classes with hierarchy <br /> keyword<br /> :reserved system word<br /> MSIL<br /> :MicroSoft Intermediary Language<br /> JIT<br /> :Just In Time compilation @ first run<br /> <br /> ==Everything is an Object==<br /> In c# everything is an object. And all objects inherit from the object class.<br /> <br /> [http://quickstarts.asp.net/QuickStartv20/util/classbrowser.aspx See object in the classbrowser]<br /> <br /> Since all objects inherit from the object class they all have some the basic functionality like a method called ToString();<br /> <br /> [http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class2/FromMono See the source for object.cs from mono] <br /> <br /> <br /> ==Basic Data Types==<br /> <br /> C# is a strongly typed language. This means every object in C# must be declared to be of a specific type. All of c# basic varible type inherit from [http://msdn2.microsoft.com/en-us/library/system.object.aspx System.Object]<br /> <br /> {{.NET Data Types}}<br /> <br /> Variables must be declared with an identifier and then initialized.<br /> <br /> ===Declaration===<br /> <br /> Declaration sets aside a named section of memory the is the proper size to hold the declared type. At this point the variable contains nothing.<br /> <br /> &lt;csharp&gt;// declare a variable<br /> int firstInt; //declares a vaiable of type int<br /> string myString; //declares a vaiable of type string&lt;/csharp&gt;<br /> <br /> ===Initialization===<br /> <br /> Initialization actually sets the variables value<br /> <br /> &lt;csharp&gt;// initialize the variable<br /> firstInt = 1;<br /> myString = &quot;Hello!&quot;;&lt;/csharp&gt;<br /> <br /> Initialization uses the assignment operator to set the value of a variable<br /> <br /> ===Assignment===<br /> The Assignment '''operator''' in c# is the '=' sign. You can assign variables like this...<br /> <br /> ==Assignment==<br /> The Assignment operator in c# is the '=' sign. You can assign variables like this...<br /> We'll learn more about operators later.<br /> <br /> other ways to do it<br /> <br /> &lt;csharp&gt;// declare some variables<br /> int secondInt, thirdInt, fourthInt;<br /> secondInt = 2;<br /> thirdInt = 3;<br /> fourthInt = 4;<br /> <br /> //declare and initialize variables in one line<br /> int myNegativeInt = -2147483648;&lt;/csharp&gt;<br /> <br /> In c# variables cannot be used unil they are initalized.<br /> For example<br /> <br /> &lt;csharp&gt;int UsedBeforeInit;<br /> Console.WriteLine(UsedBeforeInit);&lt;/csharp&gt;<br /> <br /> will produce<br /> <br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> <br /> ==Compiler Errors==<br /> error<br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> file Line .Net Framework error # and description<br /> <br /> <br /> <br /> [[Csharp warning CS0168: The variable 'NeverUsed' is declared but never used]]<br /> <br /> <br /> <br /> <br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit.cs UsedBeforeInit.cs] - example of misused variable&lt;br /&gt;<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit_Fixed.cs UsedBeforeInit_Fixed.cs] - all beter now source&lt;br /&gt;<br /> <br /> More examples of built in types<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/csharpfundamentals/1x1.cs 1x1.cs] C# intrinsic types from Learn-C-Sharp.<br /> variable.aspx - example from book aspx page View Source<br /> variable2.aspx = example from book errors View Source<br /> <br /> ==Variable Names==<br /> <br /> Variable should be named with meaningful names.<br /> <br /> for exmaple <br /> :z = x * y;<br /> <br /> does not convey any meaning<br /> <br /> but<br /> :distance = speed * time;<br /> <br /> does convey meaning.<br /> If varibales are named properly it can make your code mush easier to read.<br /> <br /> ==Naming conventions==<br /> Name variables intelligently.&lt;br&gt;<br /> Name variables with names that have meaning.&lt;br&gt;<br /> <br /> ===Hungarian Notation===<br /> Hungarian notation id a popular notation system used be many C, C++ and VB programmers. It was originally devised in Charles Simonyi's doctoral thesis, &quot;Meta-Programming: A Software Production Method.&quot; Hungarian notation specifies that a prefix be added to each variable that indicated that variables type. It also specifies sometimes adding a suffice to clarify variables meaning. In the early 1980's Microsoft adopted this notation system.<br /> <br /> <br /> ie... intHitCounter, intHitsPerMonthMax <br /> <br /> [http://msdn.microsoft.com/en-us/library/aa260976(VS.60).aspx Hungarian Notation - Charles Simonyi Microsoft]<br /> <br /> http://msdn.microsoft.com/en-us/library/ms229045.aspx<br /> <br /> '''PascalNotation'''<br /> Capitalize first Letter and then the first letter on each word. &lt;br&gt;<br /> ie... PascalNotation, IntVarName<br /> <br /> Use on method names method names.<br /> <br /> '''camelNotation'''<br /> Lower case first letter and then capitalize the first letter of each word&lt;br&gt;<br /> ie... camelNotation, intVarName<br /> <br /> use for variable names<br /> <br /> Other Coding Techniques and practices&lt;br&gt;<br /> [http://msdn.microsoft.com/en-us/library/ms229002.aspx .NET Framework Developer's Guide<br /> Guidelines for Names]&lt;br&gt;<br /> [http://www-106.ibm.com/developerworks/eserver/articles/hook_duttaC.html?ca=dgr-lnxw06BestC IBM Best Practices for Programming in C]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html GNU Coding Standards]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html#Names GNU Naming conventions]&lt;br&gt;<br /> More Types<br /> <br /> ==Operators==<br /> <br /> ECMA-334 Operators and punctuators<br /> <br /> C# uses the equals = sign for Assignment<br /> <br /> int myVar = 15; //sets the value of myVar to 15<br /> <br /> ===Mathematical Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |+ ||addition<br /> |-<br /> |- || subtraction<br /> |-<br /> |* || multiplication<br /> |-<br /> |/ || division<br /> |-<br /> |% || modulus remainder Ask Dr.Math What is Modulus?<br /> |}<br /> <br /> ===Increment Decrement Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |++ || increment same as foo = foo + 1<br /> |-<br /> | -- || decrement same as foo = foo - 1<br /> |-<br /> |+= || calculate and reassign addition<br /> |-<br /> | -= || calculate and reassign subtraction<br /> |-<br /> |*= || calculate and reassign multiplication<br /> |-<br /> |/= || calculate and reassign division<br /> |-<br /> |%= || calculate and reassign modulus<br /> |-<br /> |y= x++ || assignment prefix y is assigned to x and then x in incremented<br /> |-<br /> |y= ++x || assignment postfix x is incremented and then assigned to y<br /> |}<br /> <br /> ===Operator Precedence===<br /> Evaluated First<br /> <br /> * ++,--,unary-<br /> * *,/,%<br /> * +,-<br /> <br /> Evaluated Last<br /> <br /> * =,+=,-=,*=,etc<br /> <br /> <br /> {{csharp strings}}<br /> {{csharp string functions}}<br /> <br /> ==Short Assignment==<br /> Short in class Assignment<br /> In class assignment 10-15 mins<br /> Build a c# console app (remember to take a top down aproach start small with something you know maybe start with hello world)<br /> * Declare and initialize two integers<br /> * Display their values using Console.WriteLine<br /> * Declare a third integer and initialize it with the sum of the first two integers<br /> * Output the value of the third integer<br /> <br /> <br /> Top down development with comments [http://iam.colum.edu/oop/classsource/class2/topdown.aspx topdown.aspx]<br /> <br /> Fully implemented Console adding program [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/add.cs add.cs]<br /> <br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> <br /> namespace Hello<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Super Cool Calculatorizer&quot;);<br /> <br /> //Declare two variables<br /> int intOne;<br /> int intTwo;<br /> int intSum;<br /> <br /> //intialize the two variables<br /> intOne = 47;<br /> intTwo = 2;<br /> <br /> //Lets test the values<br /> Console.Write(&quot;Enter a integer: &quot;);<br /> intOne = int.Parse(Console.ReadLine()); //set the value of intOne <br /> //to what was typed in the console<br /> Console.Write(&quot;Enter another integer: &quot;);<br /> intTwo = int.Parse(Console.ReadLine()); //int.Parse attempts to parse a string<br /> //and convert it to an int<br /> <br /> intSum = intOne + intTwo;<br /> <br /> Console.WriteLine(&quot;intTwo + intTwo = &quot; + intSum);<br /> <br /> Console.ReadKey();<br /> <br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> ==Constants==<br /> <br /> Constants are datatypes that will be assigned a value that will be constant thought the executing of the code. You cannot change constants once they have been assigned a value.<br /> syntax<br /> <br /> &lt;csharp&gt;const type identifier = value;&lt;/csharp&gt;<br /> <br /> <br /> example<br /> <br /> &lt;csharp&gt;const int freezingPoint = 32;<br /> const int freezingPointMetric = 0;<br /> const float pi = 3.141592&lt;/csharp&gt;<br /> <br /> <br /> [[OOP Arrays]]<br /> {{csharp arrays}}<br /> <br /> <br /> ==Simple Branching==<br /> <br /> ===if===<br /> syntax<br /> <br /> &lt;csharp&gt;if (expression)<br /> // statement<br /> <br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> else {<br /> // statements<br /> }&lt;/csharp&gt;<br /> <br /> ==HomeWork==<br /> *Learning c#<br /> *Chapter 5, Chapter 6<br /> <br /> <br /> Create a simple text game that asks three questions and sets three variables. There should be a fourth variable that counts the number of correct answers. The program should run in the console and use:<br /> <br /> *Console.WriteLine<br /> *Console.ReadLine<br /> *ints, strings and ifs<br /> <br /> Analysis of Homework Project<br /> *On very structured programs like this one analysis is quite easy<br /> ** Start by identifying the steps<br /> ** Add [http://en.wikipedia.org/wiki/Pseudocode Pseudocode] as c# comments for each step<br /> ** Fill in the real syntax for each step and compile each time to make sure nothing breaks (I like to call this baby steps and I like to use this technique whenever I'm trying to implement something that is completely new to me)<br /> <br /> The pseudocode might look something like<br /> &lt;csharp&gt;using System;<br /> namespace HelloVariables<br /> {<br /> class ThreeQuestions<br /> {<br /> public static void Main()<br /> {<br /> Console.WriteLine(&quot;3 Questions&quot;);<br /> //A simple game that asks three questions and checks the answers. If the question is answered correctly we will award 1 point<br /> <br /> //Declare Variables<br /> <br /> //Ask Question 1<br /> <br /> //Read Answer<br /> <br /> //Check Answer and add 1 to points is correct<br /> <br /> //Repeat with Questions 2 and 3<br /> <br /> //Display Percent Correct<br /> <br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> ==Video==<br /> &lt;html&gt;<br /> &lt;script type='text/javascript' src='http://iam.colum.edu/videotutorials/mediaplayer-5.2/swfobject.js'&gt;&lt;/script&gt; <br /> &lt;div id='mediaspace2'&gt;This text will be replaced&lt;/div&gt; <br /> &lt;script type='text/javascript'&gt;<br /> var so = new SWFObject('http://iam.colum.edu/videotutorials/mediaplayer-5.2/player.swf','mpl','800','600','9');so.addParam('allowfullscreen','true')<br /> ;so.addParam('allowscriptaccess','always');<br /> so.addParam('wmode','opaque');<br /> so.addVariable('file','http://iam.colum.edu/videotutorials/MACFTPS.mp4');<br /> so.addVariable('autostart','false');<br /> so.write('mediaspace2');<br /> <br /> &lt;/script&gt;<br /> <br /> &lt;/html&gt;</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class2&diff=21730 OOP Class2 2013-09-16T17:34:39Z <p>Cameron.Cintron: /* Video */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> ==Posting home work and website==<br /> <br /> =C# fundamentals=<br /> <br /> Questions from week 1 reading.<br /> discussion<br /> <br /> Some pages comparing c# to other languages<br /> <br /> A Comparative Overview of C# http://genamics.com/developer/csharp_comparative.htm<br /> <br /> C# and Java: Comparing Programming Languages http://msdn.microsoft.com/en-us/library/ms836794.aspx<br /> <br /> ==Terms==<br /> <br /> CLR<br /> :Common Language Runtime<br /> namespace<br /> :organizing classes with hierarchy <br /> keyword<br /> :reserved system word<br /> MSIL<br /> :MicroSoft Intermediary Language<br /> JIT<br /> :Just In Time compilation @ first run<br /> <br /> ==Everything is an Object==<br /> In c# everything is an object. And all objects inherit from the object class.<br /> <br /> [http://quickstarts.asp.net/QuickStartv20/util/classbrowser.aspx See object in the classbrowser]<br /> <br /> Since all objects inherit from the object class they all have some the basic functionality like a method called ToString();<br /> <br /> [http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class2/FromMono See the source for object.cs from mono] <br /> <br /> <br /> ==Basic Data Types==<br /> <br /> C# is a strongly typed language. This means every object in C# must be declared to be of a specific type. All of c# basic varible type inherit from [http://msdn2.microsoft.com/en-us/library/system.object.aspx System.Object]<br /> <br /> {{.NET Data Types}}<br /> <br /> Variables must be declared with an identifier and then initialized.<br /> <br /> ===Declaration===<br /> <br /> Declaration sets aside a named section of memory the is the proper size to hold the declared type. At this point the variable contains nothing.<br /> <br /> &lt;csharp&gt;// declare a variable<br /> int firstInt; //declares a vaiable of type int<br /> string myString; //declares a vaiable of type string&lt;/csharp&gt;<br /> <br /> ===Initialization===<br /> <br /> Initialization actually sets the variables value<br /> <br /> &lt;csharp&gt;// initialize the variable<br /> firstInt = 1;<br /> myString = &quot;Hello!&quot;;&lt;/csharp&gt;<br /> <br /> Initialization uses the assignment operator to set the value of a variable<br /> <br /> ===Assignment===<br /> The Assignment '''operator''' in c# is the '=' sign. You can assign variables like this...<br /> <br /> ==Assignment==<br /> The Assignment operator in c# is the '=' sign. You can assign variables like this...<br /> We'll learn more about operators later.<br /> <br /> other ways to do it<br /> <br /> &lt;csharp&gt;// declare some variables<br /> int secondInt, thirdInt, fourthInt;<br /> secondInt = 2;<br /> thirdInt = 3;<br /> fourthInt = 4;<br /> <br /> //declare and initialize variables in one line<br /> int myNegativeInt = -2147483648;&lt;/csharp&gt;<br /> <br /> In c# variables cannot be used unil they are initalized.<br /> For example<br /> <br /> &lt;csharp&gt;int UsedBeforeInit;<br /> Console.WriteLine(UsedBeforeInit);&lt;/csharp&gt;<br /> <br /> will produce<br /> <br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> <br /> ==Compiler Errors==<br /> error<br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> file Line .Net Framework error # and description<br /> <br /> <br /> <br /> [[Csharp warning CS0168: The variable 'NeverUsed' is declared but never used]]<br /> <br /> <br /> <br /> <br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit.cs UsedBeforeInit.cs] - example of misused variable&lt;br /&gt;<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit_Fixed.cs UsedBeforeInit_Fixed.cs] - all beter now source&lt;br /&gt;<br /> <br /> More examples of built in types<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/csharpfundamentals/1x1.cs 1x1.cs] C# intrinsic types from Learn-C-Sharp.<br /> variable.aspx - example from book aspx page View Source<br /> variable2.aspx = example from book errors View Source<br /> <br /> ==Variable Names==<br /> <br /> Variable should be named with meaningful names.<br /> <br /> for exmaple <br /> :z = x * y;<br /> <br /> does not convey any meaning<br /> <br /> but<br /> :distance = speed * time;<br /> <br /> does convey meaning.<br /> If varibales are named properly it can make your code mush easier to read.<br /> <br /> ==Naming conventions==<br /> Name variables intelligently.&lt;br&gt;<br /> Name variables with names that have meaning.&lt;br&gt;<br /> <br /> ===Hungarian Notation===<br /> Hungarian notation id a popular notation system used be many C, C++ and VB programmers. It was originally devised in Charles Simonyi's doctoral thesis, &quot;Meta-Programming: A Software Production Method.&quot; Hungarian notation specifies that a prefix be added to each variable that indicated that variables type. It also specifies sometimes adding a suffice to clarify variables meaning. In the early 1980's Microsoft adopted this notation system.<br /> <br /> <br /> ie... intHitCounter, intHitsPerMonthMax <br /> <br /> [http://msdn.microsoft.com/en-us/library/aa260976(VS.60).aspx Hungarian Notation - Charles Simonyi Microsoft]<br /> <br /> http://msdn.microsoft.com/en-us/library/ms229045.aspx<br /> <br /> '''PascalNotation'''<br /> Capitalize first Letter and then the first letter on each word. &lt;br&gt;<br /> ie... PascalNotation, IntVarName<br /> <br /> Use on method names method names.<br /> <br /> '''camelNotation'''<br /> Lower case first letter and then capitalize the first letter of each word&lt;br&gt;<br /> ie... camelNotation, intVarName<br /> <br /> use for variable names<br /> <br /> Other Coding Techniques and practices&lt;br&gt;<br /> [http://msdn.microsoft.com/en-us/library/ms229002.aspx .NET Framework Developer's Guide<br /> Guidelines for Names]&lt;br&gt;<br /> [http://www-106.ibm.com/developerworks/eserver/articles/hook_duttaC.html?ca=dgr-lnxw06BestC IBM Best Practices for Programming in C]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html GNU Coding Standards]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html#Names GNU Naming conventions]&lt;br&gt;<br /> More Types<br /> <br /> ==Operators==<br /> <br /> ECMA-334 Operators and punctuators<br /> <br /> C# uses the equals = sign for Assignment<br /> <br /> int myVar = 15; //sets the value of myVar to 15<br /> <br /> ===Mathematical Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |+ ||addition<br /> |-<br /> |- || subtraction<br /> |-<br /> |* || multiplication<br /> |-<br /> |/ || division<br /> |-<br /> |% || modulus remainder Ask Dr.Math What is Modulus?<br /> |}<br /> <br /> ===Increment Decrement Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |++ || increment same as foo = foo + 1<br /> |-<br /> | -- || decrement same as foo = foo - 1<br /> |-<br /> |+= || calculate and reassign addition<br /> |-<br /> | -= || calculate and reassign subtraction<br /> |-<br /> |*= || calculate and reassign multiplication<br /> |-<br /> |/= || calculate and reassign division<br /> |-<br /> |%= || calculate and reassign modulus<br /> |-<br /> |y= x++ || assignment prefix y is assigned to x and then x in incremented<br /> |-<br /> |y= ++x || assignment postfix x is incremented and then assigned to y<br /> |}<br /> <br /> ===Operator Precedence===<br /> Evaluated First<br /> <br /> * ++,--,unary-<br /> * *,/,%<br /> * +,-<br /> <br /> Evaluated Last<br /> <br /> * =,+=,-=,*=,etc<br /> <br /> <br /> {{csharp strings}}<br /> {{csharp string functions}}<br /> <br /> ==Short Assignment==<br /> Short in class Assignment<br /> In class assignment 10-15 mins<br /> Build a c# console app (remember to take a top down aproach start small with something you know maybe start with hello world)<br /> * Declare and initialize two integers<br /> * Display their values using Console.WriteLine<br /> * Declare a third integer and initialize it with the sum of the first two integers<br /> * Output the value of the third integer<br /> <br /> <br /> Top down development with comments [http://iam.colum.edu/oop/classsource/class2/topdown.aspx topdown.aspx]<br /> <br /> Fully implemented Console adding program [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/add.cs add.cs]<br /> <br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> <br /> namespace Hello<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Super Cool Calculatorizer&quot;);<br /> <br /> //Declare two variables<br /> int intOne;<br /> int intTwo;<br /> int intSum;<br /> <br /> //intialize the two variables<br /> intOne = 47;<br /> intTwo = 2;<br /> <br /> //Lets test the values<br /> Console.Write(&quot;Enter a integer: &quot;);<br /> intOne = int.Parse(Console.ReadLine()); //set the value of intOne <br /> //to what was typed in the console<br /> Console.Write(&quot;Enter another integer: &quot;);<br /> intTwo = int.Parse(Console.ReadLine()); //int.Parse attempts to parse a string<br /> //and convert it to an int<br /> <br /> intSum = intOne + intTwo;<br /> <br /> Console.WriteLine(&quot;intTwo + intTwo = &quot; + intSum);<br /> <br /> Console.ReadKey();<br /> <br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> ==Constants==<br /> <br /> Constants are datatypes that will be assigned a value that will be constant thought the executing of the code. You cannot change constants once they have been assigned a value.<br /> syntax<br /> <br /> &lt;csharp&gt;const type identifier = value;&lt;/csharp&gt;<br /> <br /> <br /> example<br /> <br /> &lt;csharp&gt;const int freezingPoint = 32;<br /> const int freezingPointMetric = 0;<br /> const float pi = 3.141592&lt;/csharp&gt;<br /> <br /> <br /> [[OOP Arrays]]<br /> {{csharp arrays}}<br /> <br /> <br /> ==Simple Branching==<br /> <br /> ===if===<br /> syntax<br /> <br /> &lt;csharp&gt;if (expression)<br /> // statement<br /> <br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> else {<br /> // statements<br /> }&lt;/csharp&gt;<br /> <br /> ==HomeWork==<br /> *Learning c#<br /> *Chapter 5, Chapter 6<br /> <br /> <br /> Create a simple text game that asks three questions and sets three variables. There should be a fourth variable that counts the number of correct answers. The program should run in the console and use:<br /> <br /> *Console.WriteLine<br /> *Console.ReadLine<br /> *ints, strings and ifs<br /> <br /> Analysis of Homework Project<br /> *On very structured programs like this one analysis is quite easy<br /> ** Start by identifying the steps<br /> ** Add [http://en.wikipedia.org/wiki/Pseudocode Pseudocode] as c# comments for each step<br /> ** Fill in the real syntax for each step and compile each time to make sure nothing breaks (I like to call this baby steps and I like to use this technique whenever I'm trying to implement something that is completely new to me)<br /> <br /> The pseudocode might look something like<br /> &lt;csharp&gt;using System;<br /> namespace HelloVariables<br /> {<br /> class ThreeQuestions<br /> {<br /> public static void Main()<br /> {<br /> Console.WriteLine(&quot;3 Questions&quot;);<br /> //A simple game that asks three questions and checks the answers. If the question is answered correctly we will award 1 point<br /> <br /> //Declare Variables<br /> <br /> //Ask Question 1<br /> <br /> //Read Answer<br /> <br /> //Check Answer and add 1 to points is correct<br /> <br /> //Repeat with Questions 2 and 3<br /> <br /> //Display Percent Correct<br /> <br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> ==Video==<br /> <br /> &lt;html&gt;<br /> &lt;script type='text/javascript' src='http://iam.colum.edu/videotutorials/mediaplayer-5.2/swfobject.js'&gt;&lt;/script&gt; <br /> &lt;div id='mediaspace2'&gt;This text will be replaced&lt;/div&gt; <br /> &lt;script type='text/javascript'&gt;<br /> var so = new SWFObject('http://iam.colum.edu/videotutorials/mediaplayer-5.2/player.swf','mpl','800','600','9');so.addParam('allowfullscreen','true')<br /> ;so.addParam('allowscriptaccess','always');<br /> so.addParam('wmode','opaque');<br /> so.addVariable('file','http://iam.colum.edu/videotutorials/MACFTPS.mp4');<br /> so.addVariable('autostart','false');<br /> so.write('mediaspace2');<br /> <br /> &lt;/script&gt;<br /> <br /> &lt;/html&gt;<br /> <br /> <br /> Visit<br /> http://iam.colum.edu/screenz/FA13/OOP_Week_2.mp4<br /> http://iam.colum.edu/screenz/FA13/OOP_Week_2/<br /> <br /> and select OOP_Week_2.html<br /> <br /> for this weeks class video</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class2&diff=21729 OOP Class2 2013-09-16T17:32:53Z <p>Cameron.Cintron: /* Video */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> ==Posting home work and website==<br /> <br /> =C# fundamentals=<br /> <br /> Questions from week 1 reading.<br /> discussion<br /> <br /> Some pages comparing c# to other languages<br /> <br /> A Comparative Overview of C# http://genamics.com/developer/csharp_comparative.htm<br /> <br /> C# and Java: Comparing Programming Languages http://msdn.microsoft.com/en-us/library/ms836794.aspx<br /> <br /> ==Terms==<br /> <br /> CLR<br /> :Common Language Runtime<br /> namespace<br /> :organizing classes with hierarchy <br /> keyword<br /> :reserved system word<br /> MSIL<br /> :MicroSoft Intermediary Language<br /> JIT<br /> :Just In Time compilation @ first run<br /> <br /> ==Everything is an Object==<br /> In c# everything is an object. And all objects inherit from the object class.<br /> <br /> [http://quickstarts.asp.net/QuickStartv20/util/classbrowser.aspx See object in the classbrowser]<br /> <br /> Since all objects inherit from the object class they all have some the basic functionality like a method called ToString();<br /> <br /> [http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class2/FromMono See the source for object.cs from mono] <br /> <br /> <br /> ==Basic Data Types==<br /> <br /> C# is a strongly typed language. This means every object in C# must be declared to be of a specific type. All of c# basic varible type inherit from [http://msdn2.microsoft.com/en-us/library/system.object.aspx System.Object]<br /> <br /> {{.NET Data Types}}<br /> <br /> Variables must be declared with an identifier and then initialized.<br /> <br /> ===Declaration===<br /> <br /> Declaration sets aside a named section of memory the is the proper size to hold the declared type. At this point the variable contains nothing.<br /> <br /> &lt;csharp&gt;// declare a variable<br /> int firstInt; //declares a vaiable of type int<br /> string myString; //declares a vaiable of type string&lt;/csharp&gt;<br /> <br /> ===Initialization===<br /> <br /> Initialization actually sets the variables value<br /> <br /> &lt;csharp&gt;// initialize the variable<br /> firstInt = 1;<br /> myString = &quot;Hello!&quot;;&lt;/csharp&gt;<br /> <br /> Initialization uses the assignment operator to set the value of a variable<br /> <br /> ===Assignment===<br /> The Assignment '''operator''' in c# is the '=' sign. You can assign variables like this...<br /> <br /> ==Assignment==<br /> The Assignment operator in c# is the '=' sign. You can assign variables like this...<br /> We'll learn more about operators later.<br /> <br /> other ways to do it<br /> <br /> &lt;csharp&gt;// declare some variables<br /> int secondInt, thirdInt, fourthInt;<br /> secondInt = 2;<br /> thirdInt = 3;<br /> fourthInt = 4;<br /> <br /> //declare and initialize variables in one line<br /> int myNegativeInt = -2147483648;&lt;/csharp&gt;<br /> <br /> In c# variables cannot be used unil they are initalized.<br /> For example<br /> <br /> &lt;csharp&gt;int UsedBeforeInit;<br /> Console.WriteLine(UsedBeforeInit);&lt;/csharp&gt;<br /> <br /> will produce<br /> <br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> <br /> ==Compiler Errors==<br /> error<br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> file Line .Net Framework error # and description<br /> <br /> <br /> <br /> [[Csharp warning CS0168: The variable 'NeverUsed' is declared but never used]]<br /> <br /> <br /> <br /> <br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit.cs UsedBeforeInit.cs] - example of misused variable&lt;br /&gt;<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit_Fixed.cs UsedBeforeInit_Fixed.cs] - all beter now source&lt;br /&gt;<br /> <br /> More examples of built in types<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/csharpfundamentals/1x1.cs 1x1.cs] C# intrinsic types from Learn-C-Sharp.<br /> variable.aspx - example from book aspx page View Source<br /> variable2.aspx = example from book errors View Source<br /> <br /> ==Variable Names==<br /> <br /> Variable should be named with meaningful names.<br /> <br /> for exmaple <br /> :z = x * y;<br /> <br /> does not convey any meaning<br /> <br /> but<br /> :distance = speed * time;<br /> <br /> does convey meaning.<br /> If varibales are named properly it can make your code mush easier to read.<br /> <br /> ==Naming conventions==<br /> Name variables intelligently.&lt;br&gt;<br /> Name variables with names that have meaning.&lt;br&gt;<br /> <br /> ===Hungarian Notation===<br /> Hungarian notation id a popular notation system used be many C, C++ and VB programmers. It was originally devised in Charles Simonyi's doctoral thesis, &quot;Meta-Programming: A Software Production Method.&quot; Hungarian notation specifies that a prefix be added to each variable that indicated that variables type. It also specifies sometimes adding a suffice to clarify variables meaning. In the early 1980's Microsoft adopted this notation system.<br /> <br /> <br /> ie... intHitCounter, intHitsPerMonthMax <br /> <br /> [http://msdn.microsoft.com/en-us/library/aa260976(VS.60).aspx Hungarian Notation - Charles Simonyi Microsoft]<br /> <br /> http://msdn.microsoft.com/en-us/library/ms229045.aspx<br /> <br /> '''PascalNotation'''<br /> Capitalize first Letter and then the first letter on each word. &lt;br&gt;<br /> ie... PascalNotation, IntVarName<br /> <br /> Use on method names method names.<br /> <br /> '''camelNotation'''<br /> Lower case first letter and then capitalize the first letter of each word&lt;br&gt;<br /> ie... camelNotation, intVarName<br /> <br /> use for variable names<br /> <br /> Other Coding Techniques and practices&lt;br&gt;<br /> [http://msdn.microsoft.com/en-us/library/ms229002.aspx .NET Framework Developer's Guide<br /> Guidelines for Names]&lt;br&gt;<br /> [http://www-106.ibm.com/developerworks/eserver/articles/hook_duttaC.html?ca=dgr-lnxw06BestC IBM Best Practices for Programming in C]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html GNU Coding Standards]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html#Names GNU Naming conventions]&lt;br&gt;<br /> More Types<br /> <br /> ==Operators==<br /> <br /> ECMA-334 Operators and punctuators<br /> <br /> C# uses the equals = sign for Assignment<br /> <br /> int myVar = 15; //sets the value of myVar to 15<br /> <br /> ===Mathematical Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |+ ||addition<br /> |-<br /> |- || subtraction<br /> |-<br /> |* || multiplication<br /> |-<br /> |/ || division<br /> |-<br /> |% || modulus remainder Ask Dr.Math What is Modulus?<br /> |}<br /> <br /> ===Increment Decrement Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |++ || increment same as foo = foo + 1<br /> |-<br /> | -- || decrement same as foo = foo - 1<br /> |-<br /> |+= || calculate and reassign addition<br /> |-<br /> | -= || calculate and reassign subtraction<br /> |-<br /> |*= || calculate and reassign multiplication<br /> |-<br /> |/= || calculate and reassign division<br /> |-<br /> |%= || calculate and reassign modulus<br /> |-<br /> |y= x++ || assignment prefix y is assigned to x and then x in incremented<br /> |-<br /> |y= ++x || assignment postfix x is incremented and then assigned to y<br /> |}<br /> <br /> ===Operator Precedence===<br /> Evaluated First<br /> <br /> * ++,--,unary-<br /> * *,/,%<br /> * +,-<br /> <br /> Evaluated Last<br /> <br /> * =,+=,-=,*=,etc<br /> <br /> <br /> {{csharp strings}}<br /> {{csharp string functions}}<br /> <br /> ==Short Assignment==<br /> Short in class Assignment<br /> In class assignment 10-15 mins<br /> Build a c# console app (remember to take a top down aproach start small with something you know maybe start with hello world)<br /> * Declare and initialize two integers<br /> * Display their values using Console.WriteLine<br /> * Declare a third integer and initialize it with the sum of the first two integers<br /> * Output the value of the third integer<br /> <br /> <br /> Top down development with comments [http://iam.colum.edu/oop/classsource/class2/topdown.aspx topdown.aspx]<br /> <br /> Fully implemented Console adding program [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/add.cs add.cs]<br /> <br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> <br /> namespace Hello<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Super Cool Calculatorizer&quot;);<br /> <br /> //Declare two variables<br /> int intOne;<br /> int intTwo;<br /> int intSum;<br /> <br /> //intialize the two variables<br /> intOne = 47;<br /> intTwo = 2;<br /> <br /> //Lets test the values<br /> Console.Write(&quot;Enter a integer: &quot;);<br /> intOne = int.Parse(Console.ReadLine()); //set the value of intOne <br /> //to what was typed in the console<br /> Console.Write(&quot;Enter another integer: &quot;);<br /> intTwo = int.Parse(Console.ReadLine()); //int.Parse attempts to parse a string<br /> //and convert it to an int<br /> <br /> intSum = intOne + intTwo;<br /> <br /> Console.WriteLine(&quot;intTwo + intTwo = &quot; + intSum);<br /> <br /> Console.ReadKey();<br /> <br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> ==Constants==<br /> <br /> Constants are datatypes that will be assigned a value that will be constant thought the executing of the code. You cannot change constants once they have been assigned a value.<br /> syntax<br /> <br /> &lt;csharp&gt;const type identifier = value;&lt;/csharp&gt;<br /> <br /> <br /> example<br /> <br /> &lt;csharp&gt;const int freezingPoint = 32;<br /> const int freezingPointMetric = 0;<br /> const float pi = 3.141592&lt;/csharp&gt;<br /> <br /> <br /> [[OOP Arrays]]<br /> {{csharp arrays}}<br /> <br /> <br /> ==Simple Branching==<br /> <br /> ===if===<br /> syntax<br /> <br /> &lt;csharp&gt;if (expression)<br /> // statement<br /> <br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> else {<br /> // statements<br /> }&lt;/csharp&gt;<br /> <br /> ==HomeWork==<br /> *Learning c#<br /> *Chapter 5, Chapter 6<br /> <br /> <br /> Create a simple text game that asks three questions and sets three variables. There should be a fourth variable that counts the number of correct answers. The program should run in the console and use:<br /> <br /> *Console.WriteLine<br /> *Console.ReadLine<br /> *ints, strings and ifs<br /> <br /> Analysis of Homework Project<br /> *On very structured programs like this one analysis is quite easy<br /> ** Start by identifying the steps<br /> ** Add [http://en.wikipedia.org/wiki/Pseudocode Pseudocode] as c# comments for each step<br /> ** Fill in the real syntax for each step and compile each time to make sure nothing breaks (I like to call this baby steps and I like to use this technique whenever I'm trying to implement something that is completely new to me)<br /> <br /> The pseudocode might look something like<br /> &lt;csharp&gt;using System;<br /> namespace HelloVariables<br /> {<br /> class ThreeQuestions<br /> {<br /> public static void Main()<br /> {<br /> Console.WriteLine(&quot;3 Questions&quot;);<br /> //A simple game that asks three questions and checks the answers. If the question is answered correctly we will award 1 point<br /> <br /> //Declare Variables<br /> <br /> //Ask Question 1<br /> <br /> //Read Answer<br /> <br /> //Check Answer and add 1 to points is correct<br /> <br /> //Repeat with Questions 2 and 3<br /> <br /> //Display Percent Correct<br /> <br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> ==Video==<br /> <br /> &lt;html&gt;<br /> &lt;script type='text/javascript' src='http://iam.colum.edu/videotutorials/mediaplayer-5.2/swfobject.js'&gt;&lt;/script&gt; <br /> &lt;div id='mediaspace'&gt;This text will be replaced&lt;/div&gt; <br /> &lt;script type='text/javascript'&gt;<br /> var so = new SWFObject('http://iam.colum.edu/videotutorials/mediaplayer-5.2/player.swf','mpl','800','600','9');so.addParam('allowfullscreen','true')<br /> ;so.addParam('allowscriptaccess','always');<br /> so.addParam('wmode','opaque');<br /> so.addVariable('file','http://iam.colum.edu/screenz/FA13/OOP_Week_2.mp4');<br /> so.addVariable('autostart','false');<br /> so.write('mediaspace');<br /> <br /> &lt;/script&gt;<br /> <br /> &lt;/html&gt;<br /> <br /> <br /> Visit<br /> <br /> http://iam.colum.edu/screenz/FA13/OOP_Week_2/<br /> <br /> and select OOP_Week_2.html<br /> <br /> for this weeks class video</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class2&diff=21728 OOP Class2 2013-09-12T20:17:47Z <p>Cameron.Cintron: /* Video */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> ==Posting home work and website==<br /> <br /> =C# fundamentals=<br /> <br /> Questions from week 1 reading.<br /> discussion<br /> <br /> Some pages comparing c# to other languages<br /> <br /> A Comparative Overview of C# http://genamics.com/developer/csharp_comparative.htm<br /> <br /> C# and Java: Comparing Programming Languages http://msdn.microsoft.com/en-us/library/ms836794.aspx<br /> <br /> ==Terms==<br /> <br /> CLR<br /> :Common Language Runtime<br /> namespace<br /> :organizing classes with hierarchy <br /> keyword<br /> :reserved system word<br /> MSIL<br /> :MicroSoft Intermediary Language<br /> JIT<br /> :Just In Time compilation @ first run<br /> <br /> ==Everything is an Object==<br /> In c# everything is an object. And all objects inherit from the object class.<br /> <br /> [http://quickstarts.asp.net/QuickStartv20/util/classbrowser.aspx See object in the classbrowser]<br /> <br /> Since all objects inherit from the object class they all have some the basic functionality like a method called ToString();<br /> <br /> [http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class2/FromMono See the source for object.cs from mono] <br /> <br /> <br /> ==Basic Data Types==<br /> <br /> C# is a strongly typed language. This means every object in C# must be declared to be of a specific type. All of c# basic varible type inherit from [http://msdn2.microsoft.com/en-us/library/system.object.aspx System.Object]<br /> <br /> {{.NET Data Types}}<br /> <br /> Variables must be declared with an identifier and then initialized.<br /> <br /> ===Declaration===<br /> <br /> Declaration sets aside a named section of memory the is the proper size to hold the declared type. At this point the variable contains nothing.<br /> <br /> &lt;csharp&gt;// declare a variable<br /> int firstInt; //declares a vaiable of type int<br /> string myString; //declares a vaiable of type string&lt;/csharp&gt;<br /> <br /> ===Initialization===<br /> <br /> Initialization actually sets the variables value<br /> <br /> &lt;csharp&gt;// initialize the variable<br /> firstInt = 1;<br /> myString = &quot;Hello!&quot;;&lt;/csharp&gt;<br /> <br /> Initialization uses the assignment operator to set the value of a variable<br /> <br /> ===Assignment===<br /> The Assignment '''operator''' in c# is the '=' sign. You can assign variables like this...<br /> <br /> ==Assignment==<br /> The Assignment operator in c# is the '=' sign. You can assign variables like this...<br /> We'll learn more about operators later.<br /> <br /> other ways to do it<br /> <br /> &lt;csharp&gt;// declare some variables<br /> int secondInt, thirdInt, fourthInt;<br /> secondInt = 2;<br /> thirdInt = 3;<br /> fourthInt = 4;<br /> <br /> //declare and initialize variables in one line<br /> int myNegativeInt = -2147483648;&lt;/csharp&gt;<br /> <br /> In c# variables cannot be used unil they are initalized.<br /> For example<br /> <br /> &lt;csharp&gt;int UsedBeforeInit;<br /> Console.WriteLine(UsedBeforeInit);&lt;/csharp&gt;<br /> <br /> will produce<br /> <br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> <br /> ==Compiler Errors==<br /> error<br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> file Line .Net Framework error # and description<br /> <br /> <br /> <br /> [[Csharp warning CS0168: The variable 'NeverUsed' is declared but never used]]<br /> <br /> <br /> <br /> <br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit.cs UsedBeforeInit.cs] - example of misused variable&lt;br /&gt;<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit_Fixed.cs UsedBeforeInit_Fixed.cs] - all beter now source&lt;br /&gt;<br /> <br /> More examples of built in types<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/csharpfundamentals/1x1.cs 1x1.cs] C# intrinsic types from Learn-C-Sharp.<br /> variable.aspx - example from book aspx page View Source<br /> variable2.aspx = example from book errors View Source<br /> <br /> ==Variable Names==<br /> <br /> Variable should be named with meaningful names.<br /> <br /> for exmaple <br /> :z = x * y;<br /> <br /> does not convey any meaning<br /> <br /> but<br /> :distance = speed * time;<br /> <br /> does convey meaning.<br /> If varibales are named properly it can make your code mush easier to read.<br /> <br /> ==Naming conventions==<br /> Name variables intelligently.&lt;br&gt;<br /> Name variables with names that have meaning.&lt;br&gt;<br /> <br /> ===Hungarian Notation===<br /> Hungarian notation id a popular notation system used be many C, C++ and VB programmers. It was originally devised in Charles Simonyi's doctoral thesis, &quot;Meta-Programming: A Software Production Method.&quot; Hungarian notation specifies that a prefix be added to each variable that indicated that variables type. It also specifies sometimes adding a suffice to clarify variables meaning. In the early 1980's Microsoft adopted this notation system.<br /> <br /> <br /> ie... intHitCounter, intHitsPerMonthMax <br /> <br /> [http://msdn.microsoft.com/en-us/library/aa260976(VS.60).aspx Hungarian Notation - Charles Simonyi Microsoft]<br /> <br /> http://msdn.microsoft.com/en-us/library/ms229045.aspx<br /> <br /> '''PascalNotation'''<br /> Capitalize first Letter and then the first letter on each word. &lt;br&gt;<br /> ie... PascalNotation, IntVarName<br /> <br /> Use on method names method names.<br /> <br /> '''camelNotation'''<br /> Lower case first letter and then capitalize the first letter of each word&lt;br&gt;<br /> ie... camelNotation, intVarName<br /> <br /> use for variable names<br /> <br /> Other Coding Techniques and practices&lt;br&gt;<br /> [http://msdn.microsoft.com/en-us/library/ms229002.aspx .NET Framework Developer's Guide<br /> Guidelines for Names]&lt;br&gt;<br /> [http://www-106.ibm.com/developerworks/eserver/articles/hook_duttaC.html?ca=dgr-lnxw06BestC IBM Best Practices for Programming in C]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html GNU Coding Standards]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html#Names GNU Naming conventions]&lt;br&gt;<br /> More Types<br /> <br /> ==Operators==<br /> <br /> ECMA-334 Operators and punctuators<br /> <br /> C# uses the equals = sign for Assignment<br /> <br /> int myVar = 15; //sets the value of myVar to 15<br /> <br /> ===Mathematical Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |+ ||addition<br /> |-<br /> |- || subtraction<br /> |-<br /> |* || multiplication<br /> |-<br /> |/ || division<br /> |-<br /> |% || modulus remainder Ask Dr.Math What is Modulus?<br /> |}<br /> <br /> ===Increment Decrement Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |++ || increment same as foo = foo + 1<br /> |-<br /> | -- || decrement same as foo = foo - 1<br /> |-<br /> |+= || calculate and reassign addition<br /> |-<br /> | -= || calculate and reassign subtraction<br /> |-<br /> |*= || calculate and reassign multiplication<br /> |-<br /> |/= || calculate and reassign division<br /> |-<br /> |%= || calculate and reassign modulus<br /> |-<br /> |y= x++ || assignment prefix y is assigned to x and then x in incremented<br /> |-<br /> |y= ++x || assignment postfix x is incremented and then assigned to y<br /> |}<br /> <br /> ===Operator Precedence===<br /> Evaluated First<br /> <br /> * ++,--,unary-<br /> * *,/,%<br /> * +,-<br /> <br /> Evaluated Last<br /> <br /> * =,+=,-=,*=,etc<br /> <br /> <br /> {{csharp strings}}<br /> {{csharp string functions}}<br /> <br /> ==Short Assignment==<br /> Short in class Assignment<br /> In class assignment 10-15 mins<br /> Build a c# console app (remember to take a top down aproach start small with something you know maybe start with hello world)<br /> * Declare and initialize two integers<br /> * Display their values using Console.WriteLine<br /> * Declare a third integer and initialize it with the sum of the first two integers<br /> * Output the value of the third integer<br /> <br /> <br /> Top down development with comments [http://iam.colum.edu/oop/classsource/class2/topdown.aspx topdown.aspx]<br /> <br /> Fully implemented Console adding program [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/add.cs add.cs]<br /> <br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> <br /> namespace Hello<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Super Cool Calculatorizer&quot;);<br /> <br /> //Declare two variables<br /> int intOne;<br /> int intTwo;<br /> int intSum;<br /> <br /> //intialize the two variables<br /> intOne = 47;<br /> intTwo = 2;<br /> <br /> //Lets test the values<br /> Console.Write(&quot;Enter a integer: &quot;);<br /> intOne = int.Parse(Console.ReadLine()); //set the value of intOne <br /> //to what was typed in the console<br /> Console.Write(&quot;Enter another integer: &quot;);<br /> intTwo = int.Parse(Console.ReadLine()); //int.Parse attempts to parse a string<br /> //and convert it to an int<br /> <br /> intSum = intOne + intTwo;<br /> <br /> Console.WriteLine(&quot;intTwo + intTwo = &quot; + intSum);<br /> <br /> Console.ReadKey();<br /> <br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> ==Constants==<br /> <br /> Constants are datatypes that will be assigned a value that will be constant thought the executing of the code. You cannot change constants once they have been assigned a value.<br /> syntax<br /> <br /> &lt;csharp&gt;const type identifier = value;&lt;/csharp&gt;<br /> <br /> <br /> example<br /> <br /> &lt;csharp&gt;const int freezingPoint = 32;<br /> const int freezingPointMetric = 0;<br /> const float pi = 3.141592&lt;/csharp&gt;<br /> <br /> <br /> [[OOP Arrays]]<br /> {{csharp arrays}}<br /> <br /> <br /> ==Simple Branching==<br /> <br /> ===if===<br /> syntax<br /> <br /> &lt;csharp&gt;if (expression)<br /> // statement<br /> <br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> else {<br /> // statements<br /> }&lt;/csharp&gt;<br /> <br /> ==HomeWork==<br /> *Learning c#<br /> *Chapter 5, Chapter 6<br /> <br /> <br /> Create a simple text game that asks three questions and sets three variables. There should be a fourth variable that counts the number of correct answers. The program should run in the console and use:<br /> <br /> *Console.WriteLine<br /> *Console.ReadLine<br /> *ints, strings and ifs<br /> <br /> Analysis of Homework Project<br /> *On very structured programs like this one analysis is quite easy<br /> ** Start by identifying the steps<br /> ** Add [http://en.wikipedia.org/wiki/Pseudocode Pseudocode] as c# comments for each step<br /> ** Fill in the real syntax for each step and compile each time to make sure nothing breaks (I like to call this baby steps and I like to use this technique whenever I'm trying to implement something that is completely new to me)<br /> <br /> The pseudocode might look something like<br /> &lt;csharp&gt;using System;<br /> namespace HelloVariables<br /> {<br /> class ThreeQuestions<br /> {<br /> public static void Main()<br /> {<br /> Console.WriteLine(&quot;3 Questions&quot;);<br /> //A simple game that asks three questions and checks the answers. If the question is answered correctly we will award 1 point<br /> <br /> //Declare Variables<br /> <br /> //Ask Question 1<br /> <br /> //Read Answer<br /> <br /> //Check Answer and add 1 to points is correct<br /> <br /> //Repeat with Questions 2 and 3<br /> <br /> //Display Percent Correct<br /> <br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> ==Video==<br /> <br /> Visit<br /> <br /> http://iam.colum.edu/screenz/FA13/OOP_Week_2/<br /> <br /> and select OOP_Week_2.html<br /> <br /> for this weeks class video</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class2&diff=21727 OOP Class2 2013-09-12T20:17:05Z <p>Cameron.Cintron: /* Video */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> ==Posting home work and website==<br /> <br /> =C# fundamentals=<br /> <br /> Questions from week 1 reading.<br /> discussion<br /> <br /> Some pages comparing c# to other languages<br /> <br /> A Comparative Overview of C# http://genamics.com/developer/csharp_comparative.htm<br /> <br /> C# and Java: Comparing Programming Languages http://msdn.microsoft.com/en-us/library/ms836794.aspx<br /> <br /> ==Terms==<br /> <br /> CLR<br /> :Common Language Runtime<br /> namespace<br /> :organizing classes with hierarchy <br /> keyword<br /> :reserved system word<br /> MSIL<br /> :MicroSoft Intermediary Language<br /> JIT<br /> :Just In Time compilation @ first run<br /> <br /> ==Everything is an Object==<br /> In c# everything is an object. And all objects inherit from the object class.<br /> <br /> [http://quickstarts.asp.net/QuickStartv20/util/classbrowser.aspx See object in the classbrowser]<br /> <br /> Since all objects inherit from the object class they all have some the basic functionality like a method called ToString();<br /> <br /> [http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class2/FromMono See the source for object.cs from mono] <br /> <br /> <br /> ==Basic Data Types==<br /> <br /> C# is a strongly typed language. This means every object in C# must be declared to be of a specific type. All of c# basic varible type inherit from [http://msdn2.microsoft.com/en-us/library/system.object.aspx System.Object]<br /> <br /> {{.NET Data Types}}<br /> <br /> Variables must be declared with an identifier and then initialized.<br /> <br /> ===Declaration===<br /> <br /> Declaration sets aside a named section of memory the is the proper size to hold the declared type. At this point the variable contains nothing.<br /> <br /> &lt;csharp&gt;// declare a variable<br /> int firstInt; //declares a vaiable of type int<br /> string myString; //declares a vaiable of type string&lt;/csharp&gt;<br /> <br /> ===Initialization===<br /> <br /> Initialization actually sets the variables value<br /> <br /> &lt;csharp&gt;// initialize the variable<br /> firstInt = 1;<br /> myString = &quot;Hello!&quot;;&lt;/csharp&gt;<br /> <br /> Initialization uses the assignment operator to set the value of a variable<br /> <br /> ===Assignment===<br /> The Assignment '''operator''' in c# is the '=' sign. You can assign variables like this...<br /> <br /> ==Assignment==<br /> The Assignment operator in c# is the '=' sign. You can assign variables like this...<br /> We'll learn more about operators later.<br /> <br /> other ways to do it<br /> <br /> &lt;csharp&gt;// declare some variables<br /> int secondInt, thirdInt, fourthInt;<br /> secondInt = 2;<br /> thirdInt = 3;<br /> fourthInt = 4;<br /> <br /> //declare and initialize variables in one line<br /> int myNegativeInt = -2147483648;&lt;/csharp&gt;<br /> <br /> In c# variables cannot be used unil they are initalized.<br /> For example<br /> <br /> &lt;csharp&gt;int UsedBeforeInit;<br /> Console.WriteLine(UsedBeforeInit);&lt;/csharp&gt;<br /> <br /> will produce<br /> <br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> <br /> ==Compiler Errors==<br /> error<br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> file Line .Net Framework error # and description<br /> <br /> <br /> <br /> [[Csharp warning CS0168: The variable 'NeverUsed' is declared but never used]]<br /> <br /> <br /> <br /> <br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit.cs UsedBeforeInit.cs] - example of misused variable&lt;br /&gt;<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit_Fixed.cs UsedBeforeInit_Fixed.cs] - all beter now source&lt;br /&gt;<br /> <br /> More examples of built in types<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/csharpfundamentals/1x1.cs 1x1.cs] C# intrinsic types from Learn-C-Sharp.<br /> variable.aspx - example from book aspx page View Source<br /> variable2.aspx = example from book errors View Source<br /> <br /> ==Variable Names==<br /> <br /> Variable should be named with meaningful names.<br /> <br /> for exmaple <br /> :z = x * y;<br /> <br /> does not convey any meaning<br /> <br /> but<br /> :distance = speed * time;<br /> <br /> does convey meaning.<br /> If varibales are named properly it can make your code mush easier to read.<br /> <br /> ==Naming conventions==<br /> Name variables intelligently.&lt;br&gt;<br /> Name variables with names that have meaning.&lt;br&gt;<br /> <br /> ===Hungarian Notation===<br /> Hungarian notation id a popular notation system used be many C, C++ and VB programmers. It was originally devised in Charles Simonyi's doctoral thesis, &quot;Meta-Programming: A Software Production Method.&quot; Hungarian notation specifies that a prefix be added to each variable that indicated that variables type. It also specifies sometimes adding a suffice to clarify variables meaning. In the early 1980's Microsoft adopted this notation system.<br /> <br /> <br /> ie... intHitCounter, intHitsPerMonthMax <br /> <br /> [http://msdn.microsoft.com/en-us/library/aa260976(VS.60).aspx Hungarian Notation - Charles Simonyi Microsoft]<br /> <br /> http://msdn.microsoft.com/en-us/library/ms229045.aspx<br /> <br /> '''PascalNotation'''<br /> Capitalize first Letter and then the first letter on each word. &lt;br&gt;<br /> ie... PascalNotation, IntVarName<br /> <br /> Use on method names method names.<br /> <br /> '''camelNotation'''<br /> Lower case first letter and then capitalize the first letter of each word&lt;br&gt;<br /> ie... camelNotation, intVarName<br /> <br /> use for variable names<br /> <br /> Other Coding Techniques and practices&lt;br&gt;<br /> [http://msdn.microsoft.com/en-us/library/ms229002.aspx .NET Framework Developer's Guide<br /> Guidelines for Names]&lt;br&gt;<br /> [http://www-106.ibm.com/developerworks/eserver/articles/hook_duttaC.html?ca=dgr-lnxw06BestC IBM Best Practices for Programming in C]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html GNU Coding Standards]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html#Names GNU Naming conventions]&lt;br&gt;<br /> More Types<br /> <br /> ==Operators==<br /> <br /> ECMA-334 Operators and punctuators<br /> <br /> C# uses the equals = sign for Assignment<br /> <br /> int myVar = 15; //sets the value of myVar to 15<br /> <br /> ===Mathematical Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |+ ||addition<br /> |-<br /> |- || subtraction<br /> |-<br /> |* || multiplication<br /> |-<br /> |/ || division<br /> |-<br /> |% || modulus remainder Ask Dr.Math What is Modulus?<br /> |}<br /> <br /> ===Increment Decrement Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |++ || increment same as foo = foo + 1<br /> |-<br /> | -- || decrement same as foo = foo - 1<br /> |-<br /> |+= || calculate and reassign addition<br /> |-<br /> | -= || calculate and reassign subtraction<br /> |-<br /> |*= || calculate and reassign multiplication<br /> |-<br /> |/= || calculate and reassign division<br /> |-<br /> |%= || calculate and reassign modulus<br /> |-<br /> |y= x++ || assignment prefix y is assigned to x and then x in incremented<br /> |-<br /> |y= ++x || assignment postfix x is incremented and then assigned to y<br /> |}<br /> <br /> ===Operator Precedence===<br /> Evaluated First<br /> <br /> * ++,--,unary-<br /> * *,/,%<br /> * +,-<br /> <br /> Evaluated Last<br /> <br /> * =,+=,-=,*=,etc<br /> <br /> <br /> {{csharp strings}}<br /> {{csharp string functions}}<br /> <br /> ==Short Assignment==<br /> Short in class Assignment<br /> In class assignment 10-15 mins<br /> Build a c# console app (remember to take a top down aproach start small with something you know maybe start with hello world)<br /> * Declare and initialize two integers<br /> * Display their values using Console.WriteLine<br /> * Declare a third integer and initialize it with the sum of the first two integers<br /> * Output the value of the third integer<br /> <br /> <br /> Top down development with comments [http://iam.colum.edu/oop/classsource/class2/topdown.aspx topdown.aspx]<br /> <br /> Fully implemented Console adding program [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/add.cs add.cs]<br /> <br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> <br /> namespace Hello<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Super Cool Calculatorizer&quot;);<br /> <br /> //Declare two variables<br /> int intOne;<br /> int intTwo;<br /> int intSum;<br /> <br /> //intialize the two variables<br /> intOne = 47;<br /> intTwo = 2;<br /> <br /> //Lets test the values<br /> Console.Write(&quot;Enter a integer: &quot;);<br /> intOne = int.Parse(Console.ReadLine()); //set the value of intOne <br /> //to what was typed in the console<br /> Console.Write(&quot;Enter another integer: &quot;);<br /> intTwo = int.Parse(Console.ReadLine()); //int.Parse attempts to parse a string<br /> //and convert it to an int<br /> <br /> intSum = intOne + intTwo;<br /> <br /> Console.WriteLine(&quot;intTwo + intTwo = &quot; + intSum);<br /> <br /> Console.ReadKey();<br /> <br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> ==Constants==<br /> <br /> Constants are datatypes that will be assigned a value that will be constant thought the executing of the code. You cannot change constants once they have been assigned a value.<br /> syntax<br /> <br /> &lt;csharp&gt;const type identifier = value;&lt;/csharp&gt;<br /> <br /> <br /> example<br /> <br /> &lt;csharp&gt;const int freezingPoint = 32;<br /> const int freezingPointMetric = 0;<br /> const float pi = 3.141592&lt;/csharp&gt;<br /> <br /> <br /> [[OOP Arrays]]<br /> {{csharp arrays}}<br /> <br /> <br /> ==Simple Branching==<br /> <br /> ===if===<br /> syntax<br /> <br /> &lt;csharp&gt;if (expression)<br /> // statement<br /> <br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> else {<br /> // statements<br /> }&lt;/csharp&gt;<br /> <br /> ==HomeWork==<br /> *Learning c#<br /> *Chapter 5, Chapter 6<br /> <br /> <br /> Create a simple text game that asks three questions and sets three variables. There should be a fourth variable that counts the number of correct answers. The program should run in the console and use:<br /> <br /> *Console.WriteLine<br /> *Console.ReadLine<br /> *ints, strings and ifs<br /> <br /> Analysis of Homework Project<br /> *On very structured programs like this one analysis is quite easy<br /> ** Start by identifying the steps<br /> ** Add [http://en.wikipedia.org/wiki/Pseudocode Pseudocode] as c# comments for each step<br /> ** Fill in the real syntax for each step and compile each time to make sure nothing breaks (I like to call this baby steps and I like to use this technique whenever I'm trying to implement something that is completely new to me)<br /> <br /> The pseudocode might look something like<br /> &lt;csharp&gt;using System;<br /> namespace HelloVariables<br /> {<br /> class ThreeQuestions<br /> {<br /> public static void Main()<br /> {<br /> Console.WriteLine(&quot;3 Questions&quot;);<br /> //A simple game that asks three questions and checks the answers. If the question is answered correctly we will award 1 point<br /> <br /> //Declare Variables<br /> <br /> //Ask Question 1<br /> <br /> //Read Answer<br /> <br /> //Check Answer and add 1 to points is correct<br /> <br /> //Repeat with Questions 2 and 3<br /> <br /> //Display Percent Correct<br /> <br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> ==Video==<br /> <br /> Visit<br /> <br /> http://iam.colum.edu/screenz/FA13/OOP_Week_2/<br /> <br /> and select OOP_Week_2.html<br /> <br /> &lt;html&gt;<br /> &lt;script type='text/javascript' src= 'http://iam.colum.edu/screenz/FA13/OOP_Week_2/scripts/swfobject.js'&gt;&lt;/script&gt; <br /> &lt;div id='mediaspace2'&gt;This text will be replaced&lt;/div&gt; <br /> &lt;script type='text/javascript'&gt;<br /> var so = new SWFObject('http://iam.colum.edu/screenz/FA13/OOP_Week_2/OOP_Week_2_player.html','mpl','800','600','9');so.addParam('allowfullscreen','true')<br /> ;so.addParam('allowscriptaccess','always');<br /> so.addParam('wmode','opaque');<br /> so.addVariable('file','http://iam.colum.edu/screenz/FA13/OOP_Week_2/OOP_Week_2.html');<br /> so.addVariable('autostart','false');<br /> so.write('mediaspace2');<br /> <br /> &lt;/script&gt;<br /> <br /> &lt;/html&gt;</div> Cameron.Cintron https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class2&diff=21726 OOP Class2 2013-09-12T18:55:48Z <p>Cameron.Cintron: /* C# fundamentals */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> ==Posting home work and website==<br /> <br /> =C# fundamentals=<br /> <br /> Questions from week 1 reading.<br /> discussion<br /> <br /> Some pages comparing c# to other languages<br /> <br /> A Comparative Overview of C# http://genamics.com/developer/csharp_comparative.htm<br /> <br /> C# and Java: Comparing Programming Languages http://msdn.microsoft.com/en-us/library/ms836794.aspx<br /> <br /> ==Terms==<br /> <br /> CLR<br /> :Common Language Runtime<br /> namespace<br /> :organizing classes with hierarchy <br /> keyword<br /> :reserved system word<br /> MSIL<br /> :MicroSoft Intermediary Language<br /> JIT<br /> :Just In Time compilation @ first run<br /> <br /> ==Everything is an Object==<br /> In c# everything is an object. And all objects inherit from the object class.<br /> <br /> [http://quickstarts.asp.net/QuickStartv20/util/classbrowser.aspx See object in the classbrowser]<br /> <br /> Since all objects inherit from the object class they all have some the basic functionality like a method called ToString();<br /> <br /> [http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class2/FromMono See the source for object.cs from mono] <br /> <br /> <br /> ==Basic Data Types==<br /> <br /> C# is a strongly typed language. This means every object in C# must be declared to be of a specific type. All of c# basic varible type inherit from [http://msdn2.microsoft.com/en-us/library/system.object.aspx System.Object]<br /> <br /> {{.NET Data Types}}<br /> <br /> Variables must be declared with an identifier and then initialized.<br /> <br /> ===Declaration===<br /> <br /> Declaration sets aside a named section of memory the is the proper size to hold the declared type. At this point the variable contains nothing.<br /> <br /> &lt;csharp&gt;// declare a variable<br /> int firstInt; //declares a vaiable of type int<br /> string myString; //declares a vaiable of type string&lt;/csharp&gt;<br /> <br /> ===Initialization===<br /> <br /> Initialization actually sets the variables value<br /> <br /> &lt;csharp&gt;// initialize the variable<br /> firstInt = 1;<br /> myString = &quot;Hello!&quot;;&lt;/csharp&gt;<br /> <br /> Initialization uses the assignment operator to set the value of a variable<br /> <br /> ===Assignment===<br /> The Assignment '''operator''' in c# is the '=' sign. You can assign variables like this...<br /> <br /> ==Assignment==<br /> The Assignment operator in c# is the '=' sign. You can assign variables like this...<br /> We'll learn more about operators later.<br /> <br /> other ways to do it<br /> <br /> &lt;csharp&gt;// declare some variables<br /> int secondInt, thirdInt, fourthInt;<br /> secondInt = 2;<br /> thirdInt = 3;<br /> fourthInt = 4;<br /> <br /> //declare and initialize variables in one line<br /> int myNegativeInt = -2147483648;&lt;/csharp&gt;<br /> <br /> In c# variables cannot be used unil they are initalized.<br /> For example<br /> <br /> &lt;csharp&gt;int UsedBeforeInit;<br /> Console.WriteLine(UsedBeforeInit);&lt;/csharp&gt;<br /> <br /> will produce<br /> <br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> <br /> ==Compiler Errors==<br /> error<br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> file Line .Net Framework error # and description<br /> <br /> <br /> <br /> [[Csharp warning CS0168: The variable 'NeverUsed' is declared but never used]]<br /> <br /> <br /> <br /> <br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit.cs UsedBeforeInit.cs] - example of misused variable&lt;br /&gt;<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/UsedBeforeInit_Fixed.cs UsedBeforeInit_Fixed.cs] - all beter now source&lt;br /&gt;<br /> <br /> More examples of built in types<br /> [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/csharpfundamentals/1x1.cs 1x1.cs] C# intrinsic types from Learn-C-Sharp.<br /> variable.aspx - example from book aspx page View Source<br /> variable2.aspx = example from book errors View Source<br /> <br /> ==Variable Names==<br /> <br /> Variable should be named with meaningful names.<br /> <br /> for exmaple <br /> :z = x * y;<br /> <br /> does not convey any meaning<br /> <br /> but<br /> :distance = speed * time;<br /> <br /> does convey meaning.<br /> If varibales are named properly it can make your code mush easier to read.<br /> <br /> ==Naming conventions==<br /> Name variables intelligently.&lt;br&gt;<br /> Name variables with names that have meaning.&lt;br&gt;<br /> <br /> ===Hungarian Notation===<br /> Hungarian notation id a popular notation system used be many C, C++ and VB programmers. It was originally devised in Charles Simonyi's doctoral thesis, &quot;Meta-Programming: A Software Production Method.&quot; Hungarian notation specifies that a prefix be added to each variable that indicated that variables type. It also specifies sometimes adding a suffice to clarify variables meaning. In the early 1980's Microsoft adopted this notation system.<br /> <br /> <br /> ie... intHitCounter, intHitsPerMonthMax <br /> <br /> [http://msdn.microsoft.com/en-us/library/aa260976(VS.60).aspx Hungarian Notation - Charles Simonyi Microsoft]<br /> <br /> http://msdn.microsoft.com/en-us/library/ms229045.aspx<br /> <br /> '''PascalNotation'''<br /> Capitalize first Letter and then the first letter on each word. &lt;br&gt;<br /> ie... PascalNotation, IntVarName<br /> <br /> Use on method names method names.<br /> <br /> '''camelNotation'''<br /> Lower case first letter and then capitalize the first letter of each word&lt;br&gt;<br /> ie... camelNotation, intVarName<br /> <br /> use for variable names<br /> <br /> Other Coding Techniques and practices&lt;br&gt;<br /> [http://msdn.microsoft.com/en-us/library/ms229002.aspx .NET Framework Developer's Guide<br /> Guidelines for Names]&lt;br&gt;<br /> [http://www-106.ibm.com/developerworks/eserver/articles/hook_duttaC.html?ca=dgr-lnxw06BestC IBM Best Practices for Programming in C]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html GNU Coding Standards]&lt;br&gt;<br /> [http://www.gnu.org/prep/standards/standards.html#Names GNU Naming conventions]&lt;br&gt;<br /> More Types<br /> <br /> ==Operators==<br /> <br /> ECMA-334 Operators and punctuators<br /> <br /> C# uses the equals = sign for Assignment<br /> <br /> int myVar = 15; //sets the value of myVar to 15<br /> <br /> ===Mathematical Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |+ ||addition<br /> |-<br /> |- || subtraction<br /> |-<br /> |* || multiplication<br /> |-<br /> |/ || division<br /> |-<br /> |% || modulus remainder Ask Dr.Math What is Modulus?<br /> |}<br /> <br /> ===Increment Decrement Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |++ || increment same as foo = foo + 1<br /> |-<br /> | -- || decrement same as foo = foo - 1<br /> |-<br /> |+= || calculate and reassign addition<br /> |-<br /> | -= || calculate and reassign subtraction<br /> |-<br /> |*= || calculate and reassign multiplication<br /> |-<br /> |/= || calculate and reassign division<br /> |-<br /> |%= || calculate and reassign modulus<br /> |-<br /> |y= x++ || assignment prefix y is assigned to x and then x in incremented<br /> |-<br /> |y= ++x || assignment postfix x is incremented and then assigned to y<br /> |}<br /> <br /> ===Operator Precedence===<br /> Evaluated First<br /> <br /> * ++,--,unary-<br /> * *,/,%<br /> * +,-<br /> <br /> Evaluated Last<br /> <br /> * =,+=,-=,*=,etc<br /> <br /> <br /> {{csharp strings}}<br /> {{csharp string functions}}<br /> <br /> ==Short Assignment==<br /> Short in class Assignment<br /> In class assignment 10-15 mins<br /> Build a c# console app (remember to take a top down aproach start small with something you know maybe start with hello world)<br /> * Declare and initialize two integers<br /> * Display their values using Console.WriteLine<br /> * Declare a third integer and initialize it with the sum of the first two integers<br /> * Output the value of the third integer<br /> <br /> <br /> Top down development with comments [http://iam.colum.edu/oop/classsource/class2/topdown.aspx topdown.aspx]<br /> <br /> Fully implemented Console adding program [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/add.cs add.cs]<br /> <br /> &lt;csharp&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> <br /> namespace Hello<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Super Cool Calculatorizer&quot;);<br /> <br /> //Declare two variables<br /> int intOne;<br /> int intTwo;<br /> int intSum;<br /> <br /> //intialize the two variables<br /> intOne = 47;<br /> intTwo = 2;<br /> <br /> //Lets test the values<br /> Console.Write(&quot;Enter a integer: &quot;);<br /> intOne = int.Parse(Console.ReadLine()); //set the value of intOne <br /> //to what was typed in the console<br /> Console.Write(&quot;Enter another integer: &quot;);<br /> intTwo = int.Parse(Console.ReadLine()); //int.Parse attempts to parse a string<br /> //and convert it to an int<br /> <br /> intSum = intOne + intTwo;<br /> <br /> Console.WriteLine(&quot;intTwo + intTwo = &quot; + intSum);<br /> <br /> Console.ReadKey();<br /> <br /> }<br /> }<br /> }<br /> &lt;/csharp&gt;<br /> <br /> ==Constants==<br /> <br /> Constants are datatypes that will be assigned a value that will be constant thought the executing of the code. You cannot change constants once they have been assigned a value.<br /> syntax<br /> <br /> &lt;csharp&gt;const type identifier = value;&lt;/csharp&gt;<br /> <br /> <br /> example<br /> <br /> &lt;csharp&gt;const int freezingPoint = 32;<br /> const int freezingPointMetric = 0;<br /> const float pi = 3.141592&lt;/csharp&gt;<br /> <br /> <br /> [[OOP Arrays]]<br /> {{csharp arrays}}<br /> <br /> <br /> ==Simple Branching==<br /> <br /> ===if===<br /> syntax<br /> <br /> &lt;csharp&gt;if (expression)<br /> // statement<br /> <br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> else {<br /> // statements<br /> }&lt;/csharp&gt;<br /> <br /> ==HomeWork==<br /> *Learning c#<br /> *Chapter 5, Chapter 6<br /> <br /> <br /> Create a simple text game that asks three questions and sets three variables. There should be a fourth variable that counts the number of correct answers. The program should run in the console and use:<br /> <br /> *Console.WriteLine<br /> *Console.ReadLine<br /> *ints, strings and ifs<br /> <br /> Analysis of Homework Project<br /> *On very structured programs like this one analysis is quite easy<br /> ** Start by identifying the steps<br /> ** Add [http://en.wikipedia.org/wiki/Pseudocode Pseudocode] as c# comments for each step<br /> ** Fill in the real syntax for each step and compile each time to make sure nothing breaks (I like to call this baby steps and I like to use this technique whenever I'm trying to implement something that is completely new to me)<br /> <br /> The pseudocode might look something like<br /> &lt;csharp&gt;using System;<br /> namespace HelloVariables<br /> {<br /> class ThreeQuestions<br /> {<br /> public static void Main()<br /> {<br /> Console.WriteLine(&quot;3 Questions&quot;);<br /> //A simple game that asks three questions and checks the answers. If the question is answered correctly we will award 1 point<br /> <br /> //Declare Variables<br /> <br /> //Ask Question 1<br /> <br /> //Read Answer<br /> <br /> //Check Answer and add 1 to points is correct<br /> <br /> //Repeat with Questions 2 and 3<br /> <br /> //Display Percent Correct<br /> <br /> }<br /> }<br /> }&lt;/csharp&gt;<br /> <br /> ==Video==</div> Cameron.Cintron