C# Language Changes and Updates

Size: px
Start display at page:

Download "C# Language Changes and Updates"

Transcription

1 C# Language Changes and Updates C# Language Changes and Updates Objectives Discover the new C# language features. Learn about some new and useful.net classes. Understand breaking changes. Debug and build code. The files associated with this chapter are located in the following folders: Install Folder\MoreCSharp Install Folder\MoreCSharpLab Install Folder\MoreCSharpLabCompleted Learning to Program C# 2012: What's New 4-1

2 C# Language Changes and Updates Implement New Language Features While async and dynamic were the most salient features of recent C# language updates, there are a handful of other new features that you will find useful. This chapter will cover each of these new features that appeared in both C# v4.0 and C# v5.0. Named and Optional Parameters See Implementing- NewLanguage- Features.sln A named parameter lets you specify a parameter name when calling a method. Optional parameters let you choose whether to specify a parameter or not when calling a method. The following example shows how named and optional parameters work: using System; using System.Linq; namespace Named_and_Optional_Parameters class Program static void Main(string[] args) string person = "AppDev"; PrintName(name: person); PrintName( greeting: "Greetings", name: person); static void PrintName( string name, string greeting = "Hello") Console.WriteLine( "0, 1!", greeting, name); 4-2 Learning to Program C# 2012: What's New

3 Implement New Language Features The PrintName method has two parameters of type string. The second parameter, greeting, is an optional parameter. What makes greeting an optional parameter is the assignment operator with a value. This value is a default value that the method uses if the caller doesn t provide the parameter. Specify optional parameters after required parameters, except in the case of params parameters, which are always last. In Main, the code calls PrintName twice. The first PrintName doesn t include the greeting parameter. In this case, greeting defaults to the string value Hello. Another thing you might notice about the calls to PrintName is that the calls prefix arguments with a name and colon. That s how you use named parameters. The second call to PrintName reverses the parameters in the call, specifying greeting first and then name. However, C# will ensure that the code evaluates arguments in the order specified by arguments to the method. Therefore, C# evaluates greeting prior to name. The previous example deals with constant values, but the evaluation order would be important if the arguments were method calls. C# compiles the default values of optional parameters into the metadata of a calling assembly. The implications of this are that if you change the default value, you could break code that s passing the old default value to your method. Caller Information Caller information lets you pass information to another method about the code calling that method. It takes the form of attributes that decorate method parameters. Here s an example: Learning to Program C# 2012: What's New 4-3

4 C# Language Changes and Updates using System; using System.Linq; using System.Runtime.CompilerServices; namespace Caller_Information class Program static void Main(string[] args) Log("Some log message."); Console.ReadKey(); public static void Log( string message, [CallerFilePath] string filepath = "", [CallerLineNumber] int linenumber = 0, [CallerMemberName] string membername = "") Console.WriteLine( "Called from '0', line # 1" + "\nin file 2\nMessage: 3", membername, linenumber, filepath, message); The Log method in the previous code uses the three caller information attributes: CallerFilePathAttribute, CallerLineNumberAttribute, and CallerMemberNameAttribute. These attributes ensure that the decorated parameters respectively return the path of the file for the calling code, the line number of the call to this method, and the name of the method that called this method. 4-4 Learning to Program C# 2012: What's New

5 Implement New Language Features Covariance and Contravariance Covariance and contravariance describe the conversion behavior of array, delegate, and generic type arguments. Covariance preserves assignment compatibility, while contravariance reverses assignment compatibility. The following types define an inheritance hierarchy that will help demonstrate these concepts: class Pet class Cat : Pet class Dog : Pet Pet is the base class and both Cat and Dog derive from Pet. The following example uses these types to demonstrate how covariance and contravariance work: using System; using System.Collections.Generic; using System.Linq; namespace Covariance_and_Contravariance class Program static void Main() var dogs = new List<Dog>(); IEnumerable<Pet> pets = dogs; var petfunc = new Func<Pet, Pet>( pet => return pet; ); Func<Cat, Pet> catfunc = petfunc; Console.WriteLine(catFunc(new Cat())); Console.ReadKey(); Learning to Program C# 2012: What's New 4-5

6 C# Language Changes and Updates The first two statements in Main demonstrate covariance. Since Dog derives from Pet, it only makes sense that you can assign a collection of Dog to a collection of Pet. This is useful if you have a method that returns a List<Dog>. It gives the caller the freedom to call that method and handle the results any way they want, which could be in more general terms as an IEnumerable<Pet>. The next two statements in Main demonstrate contravariance. The Func defines a lambda that accepts an argument of type Pet and returns a Pet. Notice that the next line assigns the lambda to another Func, but this new Func accepts a Cat, which derives from Pet. This makes sense because if a lambda or method defines a return parameter of type Pet, the caller should have the freedom to pass in a more derived type, such as Cat or Dog. In fact, that s what happens in the following line where the parameter to Console.WriteLine calls the lambda with a Cat instance. Embedded Interop Assemblies Embedded Interop Assemblies let you include interop code in your current assembly without needing to deploy a separate Primary Interop Assembly (PIA). A PIA is a.net assembly that provides an interop layer between.net code and Component Object Model (COM) code. Traditionally, any time you want to write.net code with code written for a COM component, you need a PIA to facilitate the communication. The consequence of using PIAs is that you have one or more additional assemblies to deploy with your application. You might only use a method or two from the COM component, but that would carry the baggage of the entire PIA. 4-6 Learning to Program C# 2012: What's New

7 Implement New Language Features Embedded Interop Assemblies lighten the load by including the necessary interop code in your referencing.net assembly. To use Embedded Interop Assemblies, open the References folder in a project, right-click, and select Properties. Figure 1 shows the Properties window with Embed Interop Types. Figure 1. Set Embed Interop Types to True on the assembly properties to embed PIA types into your assembly. In this example, the current project references the Microsoft.Office.Interop.Excel assembly, which is a PIA for Excel. Set the Embed Interop Types to True. This will let you distribute your assembly without including the PIA. New Command Line Options The C# compiler has three new command-line options, listed in Table 1. Option Meaning /link /langversion Allows you to embed interop types in the current assembly without needing a reference to and deploying the associated PIA. Lets you set the language specification. /appconfig Lets you use a different configuration file than the one produced by app.config. Table 1. New command-line options. Learning to Program C# 2012: What's New 4-7

8 C# Language Changes and Updates The previous section explained how to set /link via the Embedded Interop Types property for the PIA assembly reference. You can set the /langversion through VS 2012 by double-clicking the Properties folder in the project, clicking the Build tab, clicking the Advanced button, and selecting the Language Version, as shown in Figure 2. Figure 2. Setting the language version in Visual Studio. The /appconfig is a command-line option that you use to specify which file to use as your application configuration file, e.g., /appconfig:filename. 4-8 Learning to Program C# 2012: What's New

9 Learn about Some New.NET Classes Learn about Some New.NET Classes Each new version of the.net Framework grows significantly from the last. While it s impractical to discuss everything that is new, there are a few select classes that are general enough to be useful in a large number of applications. You may or may not find a need to use the types mentioned here, but knowing about them might be very useful if you encounter the need for them. New Types of Interest See Common- Classes.sln There are a couple of new types, BigInteger and Complex, in the System.Numerics namespace for helping you work with numbers. Another type is Tuple, which allows you to hold and pass values without creating a new type. Here s an example of how these types work: using System; using System.Linq; using System.Numerics; namespace New_Types_of_Interest class Program static void Main() BigInteger bigint = int.maxvalue; BigInteger reallybigint = bigint * 100; Console.WriteLine("BigInt = " + reallybigint); Complex cmplx1 = new Complex(7, 3); Complex cmplx2 = new Complex(5, 1); Complex cmplx = cmplx1 + cmplx2; Console.WriteLine( "Complex: 0, 1", cmplx.real, cmplx.imaginary); Learning to Program C# 2012: What's New 4-9

10 C# Language Changes and Updates var tpl = new Tuple<string, int>( "Pct Complete", 100); Console.WriteLine( "Metric: 0, Value: 1", tpl.item1, tpl.item2); Console.ReadKey(); The first few lines of Main show how to use BigInteger. The code sets bigint to the maximum value of an int. Then it multiplies that by 100, pushing it over the limits of an int. This is the value of BigInteger, allowing you to work with arbitrarily large int numbers. The next four statements demonstrate the Complex type, the Complex constructor parameters accept a real and imaginary number. As expected with a numerical type, you can perform normal mathematical operations. The final example creates a Tuple, which is a strongly typed container that can hold an arbitrary collection of values. You might find this useful to create an intermediate type on the fly without defining a custom type. One drawback is that properties are named Item1, Item2, ItemN; ordered the same as the parameters to the type. For maintenance purposes, this naming scheme might not be the most desirable. However, you might find them useful in a mathematical or scientific context where you need an ordered set of values or to pass multiple values to/from a method Learning to Program C# 2012: What's New

11 Learn about Some New.NET Classes Lazy Initialization The Lazy<T> type lets you delay instantiation of an object until its first access. You can also manage how to instantiate the type. The following example shows how to use Lazy<T> for lazy initialization. using System; using System.Linq; namespace Lazy_Initialization class Program static void Main() Lazy<Calculator> lazycalc = new Lazy<Calculator>(); Console.WriteLine(lazyCalc.Value.Count); Lazy<Calculator> lazycalcinstance = new Lazy<Calculator>( () => new Calculator(84)); Console.WriteLine( lazycalcinstance.value.count); Console.ReadKey(); The first couple of statements in Main show how to use Lazy<T> to perform lazy initialization of a calculator class. The code does not instantiate Calculator in the first statement, which instantiates Lazy<T>. However, the code does instantiate calculator in the parameter to Console.WriteLine, where it s used. Notice how you can reference the Program instance through the Value property of the Lazy<Program> instance, lazycalc.value. In the first example, Lazy<T> calls the default constructor. The next statement uses an overload of the Lazy<T> constructor that accepts a lambda. This demonstrates how to call a non-default constructor. Learning to Program C# 2012: What's New 4-11

12 C# Language Changes and Updates New Generic Types The new generic types include read-only interfaces for Collections, Dictionaries, and Lists. There s also a new SortedSet type. The following code demonstrates these new types: using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; namespace New_Generic_Types class Program static void Main() IReadOnlyCollection<int> readonlycoll = new ReadOnlyCollection<int>( new List<int> 1, 1, 1 ); // error //readonlycoll[0] = 5; var set = new SortedSet<int>( new List<int> 8, 7, 9, 1, 3, 6 ); foreach (var item in set) Console.WriteLine(item); Console.ReadKey(); The first statement in Main demonstrates the IReadOnlyCollection. There is also an IReadOnlyList and IReadOnlyDictionary, both deriving from IReadOnlyCollection Learning to Program C# 2012: What's New

13 Learn about Some New.NET Classes The SortedSet lets you manage an ordered set of objects. The example prints each item in the list, which appears in sorted order on the console screen. SortedSet is useful for managing sets where you need to perform operations such as intersections, subsets, unions, and more. Learning to Program C# 2012: What's New 4-13

14 C# Language Changes and Updates Understand Breaking Changes Microsoft goes to great lengths to support backwards compatibility in their products. However, sometimes backwards compatibility isn t possible or advisable. Sometimes, there s a bug in how the compiler works and you might have written code that depends on an incorrect implementation. This section covers breaking changes that you should be aware of when upgrading to C# 5.0. Lambda Expressions See Breaking- Changes.sln VS 2010 didn t properly capture collection values in lambda expressions in a foreach loop. The following code would have printed the number three times: static void LambdasCapturingForeachIterationVariables() Console.WriteLine("\nLambdas\n"); var numbers = new int[] 1, 2, 3 ; var lambdas = new List<Action>(); foreach (var number in numbers) lambdas.add(() => Console.WriteLine(number)); foreach (var lambda in lambdas) lambda(); In VS 2012, the same code prints 1, 2, and Learning to Program C# 2012: What's New

15 Understand Breaking Changes LINQ Expressions The problem with LINQ expressions in VS 2010 was that they didn t capture foreach collection values properly. Here s an example of the type of code where the problem occurs: static void LinqCapturingForeachIterationVariables() Console.WriteLine("\nLINQ\n"); var shades = new List<string> "light", "medium", "dark" ; var colors = new List<string> "red", "green", "blue" ; var colorset = new List<IEnumerable<string>>(); foreach (var shade in shades) var combos = from color in colors select shade + " " + color; colorset.add(combos); colorset.foreach( set => foreach (var combo in set) Console.WriteLine(combo); ); In particular, notice that the LINQ query is not materialized inside of the foreach loop. If you materialized the query with something like a ToList, the problem won t appear. Learning to Program C# 2012: What's New 4-15

16 C# Language Changes and Updates The problem shows up where the last value in the shade collection displays in all collections, like this: dark red dark green dark blue dark red dark green dark blue dark red dark green dark blue VS 2012 fixes the problem, producing the following output: light red light green light blue medium red medium green medium blue dark red dark green dark blue 4-16 Learning to Program C# 2012: What's New

17 Understand Breaking Changes Named Arguments In VS 2010 expressions by named arguments would always execute first, even if the unnamed argument appeared first in the list of method parameters. The following example demonstrates the conditions where this occurs: static void SideEffectOrder() Console.WriteLine("\nSide Effect Order\n"); MyMethod( SideEffect("first"), second: SideEffect("second")); static string SideEffect(string input) Console.WriteLine(input); return input; static void MyMethod(string first, string second) The call to MyMethod, in SideEffectOrder, contains an unnamed parameter, followed by a named parameter. In VS 2010, this code would print second and then first. However, VS 2012 prints first and then second. Learning to Program C# 2012: What's New 4-17

18 C# Language Changes and Updates Overload Resolution VS 2010 didn t select the best overload when using named and optional parameters. Here s an example that demonstrates this situation: static void OverloadParams() PrintName(company: "AppDev"); static void PrintName( string name = null, object company = null) Console.WriteLine( "This overload shouldn't be called."); static void PrintName( string company = null, object name = null, params int[] moreinput) Console.WriteLine( "Called the proper PrintName overload."); OverloadParams calls PrintName with a named parameter. The PrintName methods have different types for their first and second parameters and have switched the first two parameter names. One of the PrintName overloads has a params parameter, but VS 2010 chooses the overload without the params parameter as a best overload. OverloadParams calls PrintName with a string parameter, so the overload where company is string, is the best overload, which is what VS 2012 chooses Learning to Program C# 2012: What's New

19 Understand Breaking Changes The next overloading issue occurs when VS 2010 chooses a more specific Func<T> overload given a dynamic lambda with a more specific runtime type. Here s an example: static void OverloadFunc() dynamic number = 1; Add(() => return number; ); static void Add(Func<object> lambda) Console.WriteLine( "Called the proper Add overload."); static void Add(Func<int> lambda) Console.WriteLine( "This overload shouldn't be called."); Although number, in OverloadFunc, is dynamic, its runtime type is int. VS 2010 improperly calls the Add overload that takes an int. However, dynamic and object types have identity equality. Therefore, the Func<object> overload is the best match, which VS 2012 uses. Learning to Program C# 2012: What's New 4-19

20 C# Language Changes and Updates Essential Debugging and Building Code Skills VS 2012 is relatively easy to use when loading and running a program. However, there are some essential skills in the areas of debugging and building code that are very useful to know. This module covers these areas and clarifies a few areas that you might not have known about or might have found confusing. Debugging Tips For effective debugging, you need to be able to set a breakpoint. The easiest way to set a breakpoint is to click your mouse in the gutter, which is the vertical space to the left of the editor window, shown in Figure 3. Figure 3. Click in the gutter to create a breakpoint. After setting a breakpoint, you can start debugging by selecting DEBUG Start Debugging or by pressing the F5 key. This will run the program until it reaches the breakpoint and then stop Learning to Program C# 2012: What's New

21 Essential Debugging and Building Code Skills You can customize an individual breakpoint with conditions. Right-click on the red dot in the gutter and you ll see options for Conditions, Hit Count, and more. You can use Hit Count to stop on the breakpoint after it executes a specified number of times, such as in a loop. Condition, shown in Figure 4, lets you define an expression that will make the code hit a breakpoint on that line when the expression is true. Figure 4. You can set conditions on a breakpoint. After setting a number of breakpoints, you ll want to organize and keep track of them. You can open the Breakpoints window where you manage breakpoints, shown in Figure 5, by selecting DEBUG Windows Breakpoints. Figure 5. The Breakpoints window lets you manage breakpoints. From the Breakpoints window, you can create new breakpoints, specify columns to view, and filter the list with Search. You can organize the breakpoints by right-clicking on a breakpoint and selecting Edit labels. Then you can search on labels and perform actions on the entire group of breakpoints as a whole. When the program stops, you can inspect its state by hovering over variables with a mouse or viewing debugger windows. Learning to Program C# 2012: What's New 4-21

22 C# Language Changes and Updates Debugger Windows There are various debugger windows that help inspect the state of your application. To give you an example of how the debugger windows work this section covers Locals, Autos, and Watch. Figure 6 shows the Locals window, which shows all the variables that are currently in scope. You can open the Locals window by selecting DEBUG Windows Locals. Figure 6. The Locals window shows all the variables in scope. You can view the Name, Value, and Type of each variable in the Locals window. Additionally, you can drill down on types and see their individual members. In addition to Locals, you also have two other debugger windows with the same layout, Autos and Watch. The Autos window shows you variables on the current and previous lines, which might be useful to limit the amount of data you need to see at one time. There are four Watch windows, which let you add only the variables you are interested in. You can add variables to the Watch window by either selecting the variable name in the editor and dragging into the Watch window or typing the variable or expression into the Watch window. Stepping Through Code Once you ve started a debugging session, you ll want to step through the code. There are three primary stepping movements you ll use more than others: Step Into: Stepping into code lets you move into a block of code, which could be a constructor, property, indexer, but often will be a method. Whenever you re debugging position is over a method, you can select DEBUG Step Into or press F11 to move inside the method. Step Over: If you don t want to debug a method, use Step Over, which lets you move to the next statement at the current level of the code. You can do a Step Over by selecting DEBUG Step Over or pressing F10. Step Out: Sometimes, you ll be inside of a method and will have seen everything you need. Instead of spending time stepping through the remaining parts of the method, you can do a Step Out, returning to the calling code. To perform a Step Out, select DEBUG Step Out or press SHIFT+F Learning to Program C# 2012: What's New

23 Essential Debugging and Building Code Skills There are two more useful techniques that give you more flexibility when moving around in the debugger: The Move Cursor operation allows you to reposition the location that you re debugging at in the code. For example, what if you accidentally do a Step Over on a method that you were interested in inspecting? Just do a Move Cursor by selecting the yellow arrow on the current line in the gutter and drag the cursor back up the gutter to the line you need to be on and continue debugging from there. The Run To Cursor operation allows you to run multiple statements without needing to step through each. Imagine the tedium of stepping through a foreach loop! Saving time with the Run to Cursor means that you have more time to solve other issues. You could set another breakpoint and run until you hit it, but there s a quicker way. You can solve this problem by clicking on the line you want the code to run to, right-clicking and then selecting Run To Cursor or clicking on the line and pressing CTRL+F10. Building Code The BUILD menu contains a few sections with commands that aren t immediately obvious: The Solution section, at the top, contains build options for all projects in a solution. The Project section only affects the current project, which the currently open file in the editor or the selected file in Solution Explorer specifies. The Configuration section lets you define special build configurations and how to build the configurations. Most of the options in the Solution and Project sections of the BUILD menu have parallel functionality that only differs in scope. The Build option will only compile the artifacts that are necessary to get a build. The Rebuild option will force a rebuild of every artifact, regardless of whether it s up-to-date or not. Build is typically faster than Rebuild, especially for large solutions. So your pattern of compilation might be to Build first and then Rebuild before checking in or deploying. Of course, your choice will depend on what makes sense for your situation. The Clean option removes assemblies and other generated artifacts from the output folders. Generally, Build and Rebuild will replace the output artifacts, but doing a Clean can be useful to avoid problems. Learning to Program C# 2012: What's New 4-23

24 C# Language Changes and Updates The last section of the BUILD menu deals with configurations. A build configuration is where you set compiler and other options to control various aspects of what the build produces. By default, VS 2012 ships with two build configurations, Debug and Release. You can view available configurations by selecting BUILD Configuration Manager to open the Configuration Manager window, shown in Figure 7. Figure 7. Configuration Manager lets you manage build configurations. Checking the Build column in Configuration Manager means that the specified project is included in the build. Sometimes, you don t want a project to build every time. For example, setup projects generally take a while to build because they include multiple projects and plenty of processing themselves. Also, you generally don t need to create a new setup project every time you build. So, open the configuration, and uncheck the Build for any project you don t want to build. You can always force a build by right-clicking on the project in Solution Explorer and selecting a build option, the same way the BUILD menu options work. If you need a custom configuration, select Active solution configuration and click New. This lets you start a new configuration and even base it on an existing configuration, such as Release or Build Learning to Program C# 2012: What's New

25 Essential Debugging and Building Code Skills Configuration manager is somewhat sparse in available options. The reason is that you can now customize each project in a solution, based on a specific configuration. To specify build options for a project, open the project in Solution Explorer, double-click Properties, and select the Build tab. Figure 8 shows the Build properties for a Debug configuration. Figure 8. Project properties let you manage configuration options for a project. You can select a configuration on the properties page and set options as you need. For example, switching between Debug and Release builds, you ll see differences in options such as Define DEBUG constant, Optimize code, and more. Learning to Program C# 2012: What's New 4-25

26 C# Language Changes and Updates Summary Named parameters let you identify parameters when calling a method and optional parameters let you choose whether to include a parameter. Caller information lets you pass information about the calling code to a method. Covariance and contravariance make conversion of types for arrays, delegates, and generic type arguments more natural. New command line options let you embed interop types, choose C# versions to use, and specify an alternate config file..net includes new types like BigInteger, Complex, Tuple, read-only collections interfaces, and SortedSet. You can use Lazy<T> to delay instantiation of types until first use. A handful of breaking changes make the language work as it should, but you should be aware of what they are, especially when migrating code from VS Using the VS 2012 debugger, you can set breakpoints, step through code, and watch program state. The various build options let you build only parts of an application, force a rebuild of the whole app, or clear out generated build artifacts Learning to Program C# 2012: What's New

27 Essential Debugging and Building Code Skills Questions 1. What type of parameter does the method signature MyMethod(string name = AppDev ) have? 2. Which caller information attribute provides the name of a method: CallerFilePath, CallerLineNumber, or CallerMemberName? 3. Which type of conversion behavior describes the situation where you want to return a specific type from a method, but give the caller more freedom to use the value on a less derived type: Covariance or Contravariance? 4. Which command-line option lets you embed interop assemblies? 5. Which type allows you to work with whole numbers of arbitrary size? 6. Which debugger window lets you manage a custom set of variables? Learning to Program C# 2012: What's New 4-27

28 C# Language Changes and Updates Answers 1. What type of parameter does the method signature MyMethod(string name = AppDev ) have? Optional 2. Which caller information attribute provides the name of a method: CallerFilePath, CallerLineNumber, or CallerMemberName? CallerMemberName 3. Which type of conversion behavior describes the situation where you want to return a specific type from a method, but give the caller more freedom to use the value on a less derived type: Covariance or Contravariance? Contravariance 4. Which command-line option lets you embed interop assemblies? /link 5. Which type allows you to work with whole numbers of arbitrary size? BigInteger 6. Which debugger window lets you manage a custom set of variables? Watch 4-28 Learning to Program C# 2012: What's New

29 Lab 4: C# Language Changes and Updates Lab 4: C# Language Changes and Updates Learning to Program C# 2012: What's New 4-29

30 Lab 4: C# Language Changes and Updates Lab 4 Overview In this lab you ll learn about the C# language and VS 2012 features. To complete this lab, you ll need to work through three exercises: Learn How to Use Named and Optional Parameters Create Code that Uses Various New.NET Types Perform Various Debugging Tasks Each exercise includes an Objective section that describes the purpose of the exercise. You are encouraged to try to complete the exercise from the information given in the Objective section. If you require more information to complete the exercise, the Objective section is followed by detailed step-bystep instructions Learning to Program C# 2012: What's New

31 Learn How to Use Named and Optional Parameters Learn How to Use Named and Optional Parameters Objective In this exercise, you ll learn how to use named and optional parameters. Things to Consider When code in a separate assembly calls your code with optional parameters, C# embeds those parameters in its assembly metadata. When the code calls yours, it uses the default value it stored. Therefore, if you change the default value of an optional parameter and the calling code upgrades to your new DLL, the application might not work because it s sending the old default value to your code. The only way to fix this problem is to re-compile the code. Step-by-Step Instructions 1. Open the Parameters solution in the MoreCSharpLab/Parameters folders and open the Program.cs file. 2. Create a new method, named PrintPercent that takes two parameters, a string, named percent, and a bool, named showpercentsign. void PrintPercent( double percent, bool showpercentsign) Learning to Program C# 2012: What's New 4-31

32 Lab 4: C# Language Changes and Updates 3. Inside the PrintPercent method, implement logic to display the % sign if showpercentsign is true and print percent. void PrintPercent( double percent, bool showpercentsign) string format = showpercentsign? "0:P" : "0"; Console.WriteLine(format, percent); 4. Create a new method named PrintName with three string parameters: first, last, and middle. Make middle an optional parameter that defaults to null. void PrintName( string first, string last, string middle = null) 5. Add logic to PrintName to print first, middle, and then last, but only include middle if it isn t null. void PrintName( string first, string last, string middle = null) string middlename = string.isnullorwhitespace(middle)? " " : " " + middle + " "; Console.WriteLine(first + middlename + last); 4-32 Learning to Program C# 2012: What's New

33 Learn How to Use Named and Optional Parameters 6. In the Main method, call PrintPercent, passing a double for the first parameter and true for the second. Make the second parameter, the bool, a named parameter. static void Main() var prg = new Program(); prg.printpercent(93.75, showpercentsign: true); Console.ReadKey(); 7. In the Main method, call PrintName, passing only a first and last name. static void Main() var prg = new Program(); prg.printpercent(93.75, showpercentsign: true); prg.printname("john", "Smith"); Console.ReadKey(); 8. Select DEBUG Start Debugging to run the program and observe the following output: 9, % John Smith Learning to Program C# 2012: What's New 4-33

34 Lab 4: C# Language Changes and Updates Create Code that Uses Various New.NET Types Objective In this exercise, you ll learn how to use new types in the.net Framework. Things to Consider You might or might not use all the new types in your daily software development, but they re very useful when you need them. Step-by-Step Instructions 1. Open the Types solution in the MoreCSharpLab/Types folders and then open the Program.cs file. 2. Inside the Program class, add a constructor that prints a message indicating that Program is being instantiated. public Program() Console.WriteLine("Instantiating Program."); 3. Create a new method named GetGalacticNumbers that returns a ReadOnlyCollection of Tuple. The Tuple types will be BigInteger and Complex. ReadOnlyCollection<Tuple<BigInteger, Complex>> GetGalacticNumbers() 4-34 Learning to Program C# 2012: What's New

35 Create Code that Uses Various New.NET Types 4. Inside GetGalacticNumbers, create a new List, a named list, and assign a very arbitrary Tuples. ReadOnlyCollection<Tuple<BigInteger, Complex>> GetGalacticNumbers() var list = new List<Tuple<BigInteger, Complex>> new Tuple<BigInteger, Complex>(2, 3), new Tuple<BigInteger, Complex>( 2, new Complex(8, 7)), new Tuple<BigInteger, Complex>( (BigInteger)int.MaxValue * 2, 13) ; 5. Call AsReadOnly on the List to return a ReadOnlyCollection from GetGalacticNumbers. ReadOnlyCollection<Tuple<BigInteger, Complex>> GetGalacticNumbers() var list = new List<Tuple<BigInteger, Complex>> new Tuple<BigInteger, Complex>(2, 3), new Tuple<BigInteger, Complex>( 2, new Complex(8, 7)), new Tuple<BigInteger, Complex>( (BigInteger)int.MaxValue * 2, 13) ; return list.asreadonly(); Learning to Program C# 2012: What's New 4-35

36 Lab 4: C# Language Changes and Updates 6. Create a new method named SumGalacticNumbers that accepts a ReadOnlyCollection interface and returns a Tuple of BigInteger and of Complex. public Tuple<BigInteger, Complex> SumGalacticNumbers( IReadOnlyCollection<Tuple<BigInteger, Complex>> faroutnumbers) 7. Implement the SumGalacticNumbers to iterate through the collection, adding all the BigInteger values and adding all the Complex values. public Tuple<BigInteger, Complex> SumGalacticNumbers( IReadOnlyCollection<Tuple<BigInteger, Complex>> faroutnumbers) BigInteger bigintsum = 0; Complex complexsum = 0; foreach (var faroutnum in faroutnumbers) bigintsum += faroutnum.item1; complexsum += faroutnum.item2; 4-36 Learning to Program C# 2012: What's New

37 Create Code that Uses Various New.NET Types 8. Instantiate a new Tuple of BigInteger and of Complex and return the new Tuple. public Tuple<BigInteger, Complex> SumGalacticNumbers( IReadOnlyCollection<Tuple<BigInteger, Complex>> faroutnumbers) BigInteger bigintsum = 0; Complex complexsum = 0; foreach (var faroutnum in faroutnumbers) bigintsum += faroutnum.item1; complexsum += faroutnum.item2; return new Tuple<BigInteger,Complex>( bigintsum, complexsum); 9. In the Main method, instantiate a new Lazy of Program. static void Main() var lazyprogram = new Lazy<Program>(); Console.ReadKey(); Learning to Program C# 2012: What's New 4-37

38 Lab 4: C# Language Changes and Updates 10. Print a message that Lazy hasn t been instantiated yet. static void Main() var lazyprogram = new Lazy<Program>(); Console.WriteLine("Program not instantiated yet."); Console.ReadKey(); 11. Call the GetGalacticNumbers method and assign the result to a variable named galacticnumbers of type IReadOnlyCollection of Tuple of BigInteger and of Complex. static void Main() var lazyprogram = new Lazy<Program>(); Console.WriteLine( "Program not instantiated yet."); IReadOnlyList<Tuple<BigInteger, Complex>> galacticnumbers = lazyprogram.value.getgalacticnumbers(); Console.ReadKey(); 4-38 Learning to Program C# 2012: What's New

39 Create Code that Uses Various New.NET Types 12. Call the SumGalacticNumbers method, passing the galacticnumbers, and assigning the result to a variable named galacticnumbertotals of type Tuple of BigInteger and of Complex. static void Main() var lazyprogram = new Lazy<Program>(); Console.WriteLine("Program not instantiated yet."); IReadOnlyList<Tuple<BigInteger, Complex>> galacticnumbers = lazyprogram.value. GetGalacticNumbers(); Tuple<BigInteger, Complex> galacticnumbertotals = lazyprogram.value.sumgalacticnumbers(galacticnumbers); Console.ReadKey(); 13. Print the totals from galacticnumbertotals. static void Main() var lazyprogram = new Lazy<Program>(); Console.WriteLine("Program not instantiated yet."); IReadOnlyList<Tuple<BigInteger, Complex>> galacticnumbers = lazyprogram.value.getgalacticnumbers(); Tuple<BigInteger, Complex> galacticnumbertotals = lazyprogram.value.sumgalacticnumbers(galacticnumbers); Learning to Program C# 2012: What's New 4-39

40 Lab 4: C# Language Changes and Updates Console.WriteLine( "Totals - BigInteger: 0, Complex: 1", galacticnumbertotals.item1, galacticnumbertotals.item2); Console.ReadKey(); 14. Select DEBUG Start Debugging and observe the following output: Program not instantiated yet. Instantiating Program. Totals - BigInteger: , Complex: (24, 7) 4-40 Learning to Program C# 2012: What's New

41 Perform Various Debugging Tasks Perform Various Debugging Tasks Objective In this exercise, you ll learn some skills for working with the debugger. Things to Consider In addition to being able to debug programs, the debugging tools are excellent for stepping through and learning unfamiliar code. Step-by-Step Instructions 1. Open the Debugging solution in the MoreCSharpLab/Debugging folders and open the Program.cs file. 2. Set a breakpoint at the first line of Main that instantiates Program as prg. 3. Select DEBUG Start Debugging and observe that the program stops on the breakpoint. 4. Select DEBUG Windows Locals and observe that args and prg appear in the window. Look at their values and observe that prg is null. 5. Press F10 and observe that the debugger steps to the next statement and that prg is now an instance of Program in the Locals window. 6. Press F11 and observe that the program steps into the DoProcessing method. Observe that the Locals window shows this and accumulator. 7. Select DEBUG Windows Autos and observe that only this appears in the Autos window. 8. Press F10 and observe that accumulator and this appear in the Autos window and that the Locals window hasn t changed. 9. Press F10 and observe that accumulator is no longer in the Autos window, but i and this are. Also, observe that this, i, and accumulator are in the Locals window. 10. Press F10 three more times and observe that the debugger is on the statement inside the for loop, both Autos and Locals contain the same variables, though the order is different, and that the values of accumulator and i are Press F10 five more times and observe that the value of i is Press F10 one more time and observe that the value of accumulator is Press F10 five more times and observe that the value of i is 2 and accumulator is Set a breakpoint on the statement inside the for loop. Learning to Program C# 2012: What's New 4-41

42 Lab 4: C# Language Changes and Updates 15. Right-click on the red dot in the gutter for the breakpoint inside the for loop and select Hit Count. Select break when hit count is equal to, type 4, and click OK. 16. Press F5 and observe that the program breaks on the statement inside the for loop. Observe that the value of i is 6 and accumulator is Select DEBUG Windows Watch Watch1. Click in the Name column of the watch window, type accumulator + i, and observe that the value is Double-click on accumulator to select it. Then drag accumulator to the Watch window in the second line, below the expression you just added. Observe that the value of accumulator is Press F10 and observe that the expression value is 27 and that the accumulator value is Click your cursor on the Console.WriteLine statement, following the for loop, and press CTRL+F10. Observe that the debugger executes the remaining part of the loop and breaks on the Console.WriteLine statement. 21. Press SHIFT+F11 and observe that the program completes executing the DoProcessing method (you can see the console printout) and the debugger breaks on the call to DoProcessing in Main. 22. Press F10 and observe that the debugger moves to the final line of the Main method. 23. Select DEBUG Stop Debugging and observe that VS 2012 stops your debugging session Learning to Program C# 2012: What's New

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

Programming Logic - Beginning

Programming Logic - Beginning Programming Logic - Beginning 152-101 Debugging Applications Quick Links & Text References Debugging Concepts Pages Debugging Terminology Pages Debugging in Visual Studio Pages Breakpoints Pages Watches

More information

The NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software.

The NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software. Introduction to Netbeans This document is a brief introduction to writing and compiling a program using the NetBeans Integrated Development Environment (IDE). An IDE is a program that automates and makes

More information

Setting up a Project and Debugging with Visual Studio

Setting up a Project and Debugging with Visual Studio Setting up a Project and Debugging with Visual Studio Contents Setup Visual Studio to compile a DLL ---------------------------------------------------------------- 1 Step 1: Install Visual Studio Express

More information

Lab 8 - Vectors, and Debugging. Directions

Lab 8 - Vectors, and Debugging. Directions Lab 8 - Vectors, and Debugging. Directions The labs are marked based on attendance and effort. It is your responsibility to ensure the TA records your progress by the end of the lab. While completing these

More information

C# Programming in the.net Framework

C# Programming in the.net Framework 50150B - Version: 2.1 04 May 2018 C# Programming in the.net Framework C# Programming in the.net Framework 50150B - Version: 2.1 6 days Course Description: This six-day instructor-led course provides students

More information

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial A Walkthrough with Examples CMSC 212 - Spring 2009 Last modified March 22, 2009 What is gdb? GNU Debugger A debugger for several languages, including C and C++ It allows you to inspect what the program

More information

Justification for Names and Optional Parameters

Justification for Names and Optional Parameters Justification for Names and Optional Parameters By Bill Wagner March 2012 Many developers ask why named and optional parameters were not added earlier to the C# language. As other languages have shown,

More information

Getting started 7. Storing values 21. Creating variables 22 Reading input 24 Employing arrays 26 Casting data types 28 Fixing constants 30 Summary 32

Getting started 7. Storing values 21. Creating variables 22 Reading input 24 Employing arrays 26 Casting data types 28 Fixing constants 30 Summary 32 Contents 1 2 3 Contents Getting started 7 Introducing C# 8 Installing Visual Studio 10 Exploring the IDE 12 Starting a Console project 14 Writing your first program 16 Following the rules 18 Summary 20

More information

Engr 123 Spring 2018 Notes on Visual Studio

Engr 123 Spring 2018 Notes on Visual Studio Engr 123 Spring 2018 Notes on Visual Studio We will be using Microsoft Visual Studio 2017 for all of the programming assignments in this class. Visual Studio is available on the campus network. For your

More information

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led CENTER OF KNOWLEDGE, PATH TO SUCCESS Website: PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO 2010 Course: 10550A; Duration: 5 Days; Instructor-led WHAT YOU WILL LEARN This course teaches you

More information

Customizing DAZ Studio

Customizing DAZ Studio Customizing DAZ Studio This tutorial covers from the beginning customization options such as setting tabs to the more advanced options such as setting hot keys and altering the menu layout. Introduction:

More information

Upcoming Features in C# Mads Torgersen, MSFT

Upcoming Features in C# Mads Torgersen, MSFT Upcoming Features in C# Mads Torgersen, MSFT This document describes language features currently planned for C# 6, the next version of C#. All of these are implemented and available in VS 2015 Preview.

More information

A Tutorial for ECE 175

A Tutorial for ECE 175 Debugging in Microsoft Visual Studio 2010 A Tutorial for ECE 175 1. Introduction Debugging refers to the process of discovering defects (bugs) in software and correcting them. This process is invoked when

More information

Introduction to C/C++ Programming

Introduction to C/C++ Programming Chapter 1 Introduction to C/C++ Programming This book is about learning numerical programming skill and the software development process. Therefore, it requires a lot of hands-on programming exercises.

More information

Introduction. Key features and lab exercises to familiarize new users to the Visual environment

Introduction. Key features and lab exercises to familiarize new users to the Visual environment Introduction Key features and lab exercises to familiarize new users to the Visual environment January 1999 CONTENTS KEY FEATURES... 3 Statement Completion Options 3 Auto List Members 3 Auto Type Info

More information

Course Syllabus C # Course Title. Who should attend? Course Description

Course Syllabus C # Course Title. Who should attend? Course Description Course Title C # Course Description C # is an elegant and type-safe object-oriented language that enables developers to build a variety of secure and robust applications that run on the.net Framework.

More information

Using the Xcode Debugger

Using the Xcode Debugger g Using the Xcode Debugger J Objectives In this appendix you ll: Set breakpoints and run a program in the debugger. Use the Continue program execution command to continue execution. Use the Auto window

More information

10266 Programming in C Sharp with Microsoft Visual Studio 2010

10266 Programming in C Sharp with Microsoft Visual Studio 2010 10266 Programming in C Sharp with Microsoft Visual Studio 2010 Course Number: 10266A Category: Visual Studio 2010 Duration: 5 days Course Description The course focuses on C# program structure, language

More information

12/14/2016. Errors. Debugging and Error Handling. Run-Time Errors. Debugging in C# Debugging in C# (continued)

12/14/2016. Errors. Debugging and Error Handling. Run-Time Errors. Debugging in C# Debugging in C# (continued) Debugging and Error Handling Debugging methods available in the ID Error-handling techniques available in C# Errors Visual Studio IDE reports errors as soon as it is able to detect a problem Error message

More information

Programming in Visual Basic with Microsoft Visual Studio 2010

Programming in Visual Basic with Microsoft Visual Studio 2010 Programming in Visual Basic with Microsoft Visual Studio 2010 Course 10550; 5 Days, Instructor-led Course Description This course teaches you Visual Basic language syntax, program structure, and implementation

More information

2 Getting Started. Getting Started (v1.8.6) 3/5/2007

2 Getting Started. Getting Started (v1.8.6) 3/5/2007 2 Getting Started Java will be used in the examples in this section; however, the information applies to all supported languages for which you have installed a compiler (e.g., Ada, C, C++, Java) unless

More information

A Quick Tour GETTING STARTED WHAT S IN THIS CHAPTER?

A Quick Tour GETTING STARTED WHAT S IN THIS CHAPTER? 1 A Quick Tour WHAT S IN THIS CHAPTER? Installing and getting started with Visual Studio 2012 Creating and running your fi rst application Debugging and deploying an application Ever since software has

More information

Fundamental C# Programming

Fundamental C# Programming Part 1 Fundamental C# Programming In this section you will find: Chapter 1: Introduction to C# Chapter 2: Basic C# Programming Chapter 3: Expressions and Operators Chapter 4: Decisions, Loops, and Preprocessor

More information

Getting Started (1.8.7) 9/2/2009

Getting Started (1.8.7) 9/2/2009 2 Getting Started For the examples in this section, Microsoft Windows and Java will be used. However, much of the information applies to other operating systems and supported languages for which you have

More information

Diving into Visual Studio 2015 (Day #5): Debugging Improvements in Visual Studio 2015 (Part 1) -Akhil Mittal

Diving into Visual Studio 2015 (Day #5): Debugging Improvements in Visual Studio 2015 (Part 1) -Akhil Mittal Diving into Visual Studio 2015 (Day #5): Debugging Improvements in Visual Studio 2015 (Part 1) -Akhil Mittal Introduction Visual Studio has always been a great IDE for code debugging. It provides a numerous

More information

Part I. Integrated Development Environment. Chapter 2: The Solution Explorer, Toolbox, and Properties. Chapter 3: Options and Customizations

Part I. Integrated Development Environment. Chapter 2: The Solution Explorer, Toolbox, and Properties. Chapter 3: Options and Customizations Part I Integrated Development Environment Chapter 1: A Quick Tour Chapter 2: The Solution Explorer, Toolbox, and Properties Chapter 3: Options and Customizations Chapter 4: Workspace Control Chapter 5:

More information

CHAPTER 1: INTRODUCING C# 3

CHAPTER 1: INTRODUCING C# 3 INTRODUCTION xix PART I: THE OOP LANGUAGE CHAPTER 1: INTRODUCING C# 3 What Is the.net Framework? 4 What s in the.net Framework? 4 Writing Applications Using the.net Framework 5 What Is C#? 8 Applications

More information

Course Hours

Course Hours Programming the.net Framework 4.0/4.5 with C# 5.0 Course 70240 40 Hours Microsoft's.NET Framework presents developers with unprecedented opportunities. From 'geoscalable' web applications to desktop and

More information

Previous C# Releases. C# 3.0 Language Features. C# 3.0 Features. C# 3.0 Orcas. Local Variables. Language Integrated Query 3/23/2007

Previous C# Releases. C# 3.0 Language Features. C# 3.0 Features. C# 3.0 Orcas. Local Variables. Language Integrated Query 3/23/2007 Previous C# Releases C# 3.0 Language Features C# Programming March 12, 2007 1.0 2001 1.1 2003 2.0 2005 Generics Anonymous methods Iterators with yield Static classes Covariance and contravariance for delegate

More information

Microsoft Visual Studio 2010

Microsoft Visual Studio 2010 Microsoft Visual Studio 2010 A Beginner's Guide Joe Mayo Mc Grauu Hill New York Chicago San Francisco Lisbon London Madrid Mexico City Milan New Delhi San Juan Seoul Singapore Sydney Toronto Contents ACKNOWLEDGMENTS

More information

C++ for Everyone, 2e, Cay Horstmann, Copyright 2012 John Wiley and Sons, Inc. All rights reserved. Using a Debugger WE5.

C++ for Everyone, 2e, Cay Horstmann, Copyright 2012 John Wiley and Sons, Inc. All rights reserved. Using a Debugger WE5. Using a Debugger WE5 W o r k E D E x a m p l e 5.2 Using a Debugger As you have undoubtedly realized by now, computer programs rarely run perfectly the first time. At times, it can be quite frustrating

More information

Laboratory Assignment #4 Debugging in Eclipse CDT 1

Laboratory Assignment #4 Debugging in Eclipse CDT 1 Lab 4 (10 points) November 20, 2013 CS-2301, System Programming for Non-majors, B-term 2013 Objective Laboratory Assignment #4 Debugging in Eclipse CDT 1 Due: at 11:59 pm on the day of your lab session

More information

SQL Server. Management Studio. Chapter 3. In This Chapter. Management Studio. c Introduction to SQL Server

SQL Server. Management Studio. Chapter 3. In This Chapter. Management Studio. c Introduction to SQL Server Chapter 3 SQL Server Management Studio In This Chapter c Introduction to SQL Server Management Studio c Using SQL Server Management Studio with the Database Engine c Authoring Activities Using SQL Server

More information

CS354 gdb Tutorial Written by Chris Feilbach

CS354 gdb Tutorial Written by Chris Feilbach CS354 gdb Tutorial Written by Chris Feilbach Purpose This tutorial aims to show you the basics of using gdb to debug C programs. gdb is the GNU debugger, and is provided on systems that

More information

Windows Presentation Foundation Programming Using C#

Windows Presentation Foundation Programming Using C# Windows Presentation Foundation Programming Using C# Duration: 35 hours Price: $750 Delivery Option: Attend training via an on-demand, self-paced platform paired with personal instructor facilitation.

More information

the NXT-G programming environment

the NXT-G programming environment 2 the NXT-G programming environment This chapter takes a close look at the NXT-G programming environment and presents a few simple programs. The NXT-G programming environment is fairly complex, with lots

More information

I want to buy the book NOW!

I want to buy the book NOW! I want to buy the book NOW! Jonas Fagerberg Feel free to give this document to anyone you think can have use of the information. This document must NOT be altered in any way if you distribute it, it must

More information

ICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit

ICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit ICOM 4015 Advanced Programming Laboratory Chapter 1 Introduction to Eclipse, Java and JUnit University of Puerto Rico Electrical and Computer Engineering Department by Juan E. Surís 1 Introduction This

More information

C# Programming for Developers Course Labs Contents

C# Programming for Developers Course Labs Contents C# Programming for Developers Course Labs Contents C# Programming for Developers...1 Course Labs Contents...1 Introduction to C#...3 Aims...3 Your First C# Program...3 C# The Basics...5 The Aims...5 Declaring

More information

Basic Keywords Practice Session

Basic Keywords Practice Session Basic Keywords Practice Session Introduction In this article from my free Java 8 course, we will apply what we learned in my Java 8 Course Introduction to our first real Java program. If you haven t yet,

More information

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations , 1 C#.Net VT 2009 Course Contents C# 6 hp approx. BizTalk 1,5 hp approx. No exam, but laborations Course contents Architecture Visual Studio Syntax Classes Forms Class Libraries Inheritance Other C# essentials

More information

Visual Studio.NET. Although it is possible to program.net using only the command OVERVIEW OF VISUAL STUDIO.NET

Visual Studio.NET. Although it is possible to program.net using only the command OVERVIEW OF VISUAL STUDIO.NET Chapter. 03 9/17/01 6:08 PM Page 35 Visual Studio.NET T H R E E Although it is possible to program.net using only the command line compiler, it is much easier and more enjoyable to use Visual Studio.NET.

More information

CS 150 Lab 3 Arithmetic and the Debugger. Lab 3.0 We are going to begin using the Visual Studio 2017 debugger to aid with debugging programs.

CS 150 Lab 3 Arithmetic and the Debugger. Lab 3.0 We are going to begin using the Visual Studio 2017 debugger to aid with debugging programs. CS 150 Lab 3 Arithmetic and the Debugger The main objective of today s lab is to use some basic mathematics to solve a few real world problems. In doing so, you are to begin getting accustomed to using

More information

INFORMATICS LABORATORY WORK #2

INFORMATICS LABORATORY WORK #2 KHARKIV NATIONAL UNIVERSITY OF RADIO ELECTRONICS INFORMATICS LABORATORY WORK #2 SIMPLE C# PROGRAMS Associate Professor A.S. Eremenko, Associate Professor A.V. Persikov 2 Simple C# programs Objective: writing

More information

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo Learning C# 3.0 Jesse Liberty and Brian MacDonald O'REILLY Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo Table of Contents Preface xv 1. C# and.net Programming 1 Installing C# Express 2 C# 3.0

More information

Creating and Running Your First C# Program

Creating and Running Your First C# Program Creating and Running Your First C# Program : http://eembdersler.wordpress.com Choose the EEE-425Programming Languages (Fall) Textbook reading schedule Pdf lecture notes Updated class syllabus Midterm and

More information

ASP.NET Web Forms Programming Using Visual Basic.NET

ASP.NET Web Forms Programming Using Visual Basic.NET ASP.NET Web Forms Programming Using Visual Basic.NET Duration: 35 hours Price: $750 Delivery Option: Attend training via an on-demand, self-paced platform paired with personal instructor facilitation.

More information

EEE-425 Programming Languages (2013) 1

EEE-425 Programming Languages (2013) 1 Creating and Running Your First C# Program : http://eembdersler.wordpress.com Choose the EEE-425Programming Languages (Fall) Textbook reading schedule Pdf lecture notes Updated class syllabus Midterm and

More information

Creating a Class Library You should have your favorite version of Visual Studio open. Richard Kidwell. CSE 4253 Programming in C# Worksheet #2

Creating a Class Library You should have your favorite version of Visual Studio open. Richard Kidwell. CSE 4253 Programming in C# Worksheet #2 Worksheet #2 Overview For this worksheet, we will create a class library and then use the resulting dynamic link library (DLL) in a console application. This worksheet is a start on your next programming

More information

CS 201 Software Development Methods Spring Tutorial #1. Eclipse

CS 201 Software Development Methods Spring Tutorial #1. Eclipse CS 201 Software Development Methods Spring 2005 Tutorial #1 Eclipse Written by Matthew Spear and Joseph Calandrino Edited by Christopher Milner and Benjamin Taitelbaum ECLIPSE 3.0 DEVELOPING A SIMPLE PROGRAM

More information

Computer Science II Lab 3 Testing and Debugging

Computer Science II Lab 3 Testing and Debugging Computer Science II Lab 3 Testing and Debugging Introduction Testing and debugging are important steps in programming. Loosely, you can think of testing as verifying that your program works and debugging

More information

Introduction to Computation and Problem Solving

Introduction to Computation and Problem Solving Class 3: The Eclipse IDE Introduction to Computation and Problem Solving Prof. Steven R. Lerman and Dr. V. Judson Harward What is an IDE? An integrated development environment (IDE) is an environment in

More information

EEE-425 Programming Languages (2013) 1

EEE-425 Programming Languages (2013) 1 2 Computer programming: creating a sequence of instructions to enable the computer to do something Programmers do not use machine language when creating computer programs. Instead, programmers tend to

More information

Debugging Code in Access 2002

Debugging Code in Access 2002 0672321025 AppA 10/24/01 3:53 PM Page 1 Debugging Code in Access 2002 APPENDIX A IN THIS APPENDIX Setting the Correct Module Options for Maximum Debugging Power 2 Using the Immediate Window 6 Stopping

More information

Outline. Debugging. In Class Exercise Solution. Review If Else If. Immediate Program Errors. Function Test Example

Outline. Debugging. In Class Exercise Solution. Review If Else If. Immediate Program Errors. Function Test Example Debugging Larry Caretto Mechanical Engineering 209 Computer Programming for Mechanical Engineers February 16, 2017 Outline Review choice statements Finding and correcting program errors Debugging toolbar

More information

The C# Programming Language. Overview

The C# Programming Language. Overview The C# Programming Language Overview Microsoft's.NET Framework presents developers with unprecedented opportunities. From web applications to desktop and mobile platform applications - all can be built

More information

Under the Debug menu, there are two menu items for executing your code: the Start (F5) option and the

Under the Debug menu, there are two menu items for executing your code: the Start (F5) option and the CS106B Summer 2013 Handout #07P June 24, 2013 Debugging with Visual Studio This handout has many authors including Eric Roberts, Julie Zelenski, Stacey Doerr, Justin Manis, Justin Santamaria, and Jason

More information

1.00 Lecture 2. What s an IDE?

1.00 Lecture 2. What s an IDE? 1.00 Lecture 2 Interactive Development Environment: Eclipse Reading for next time: Big Java: sections 3.1-3.9 (Pretend the method is main() in each example) What s an IDE? An integrated development environment

More information

Programming in C# with Microsoft Visual Studio 2010

Programming in C# with Microsoft Visual Studio 2010 Programming in C# with Microsoft Visual Studio 2010 Course 10266; 5 Days, Instructor-led Course Description: The course focuses on C# program structure, language syntax, and implementation details with.net

More information

Getting Started. 1 by Conner Irwin

Getting Started. 1 by Conner Irwin If you are a fan of the.net family of languages C#, Visual Basic, and so forth and you own a copy of AGK, then you ve got a new toy to play with. The AGK Wrapper for.net is an open source project that

More information

Using Expressions Effectively

Using Expressions Effectively Using Expressions Effectively By Kevin Hazzard and Jason Bock, author of Metaprogramming in.net Writing code in IL can easily lead to incorrect implementations and requires a mental model of code execution

More information

Walkthrough Using the New CLR Interop Feature of Microsoft Dynamics AX

Walkthrough Using the New CLR Interop Feature of Microsoft Dynamics AX Walkthrough Using the New CLR Interop Feature of Microsoft Dynamics AX Walkthrough Using the New CLR Interop Feature of Microsoft Dynamics AX Lab Manual Table of Contents Lab 1: CLR Interop... 1 Lab Objective...

More information

Creating a new CDC policy using the Database Administration Console

Creating a new CDC policy using the Database Administration Console Creating a new CDC policy using the Database Administration Console When you start Progress Developer Studio for OpenEdge for the first time, you need to specify a workspace location. A workspace is a

More information

AlphaSmart Manager 2. User s Guide

AlphaSmart Manager 2. User s Guide AlphaSmart Manager 2 User s Guide AlphaSmart Sales and Technical Support For AlphaSmart sales and technical support contact information, see page 81 or visit the AlphaSmart web site at www.alphasmart.com

More information

Using EnScript to Make Your Life Easier Session 1. Suzanne Widup, James Habben, Bill Taroli

Using EnScript to Make Your Life Easier Session 1. Suzanne Widup, James Habben, Bill Taroli Using EnScript to Make Your Life Easier Session 1 Suzanne Widup, James Habben, Bill Taroli 1 Master Title Session 1 Getting Started with EnScript 2 EnScript Basics To Begin With EnScript is similar to

More information

Intro to MS Visual C++ Debugging

Intro to MS Visual C++ Debugging Intro to MS Visual C++ Debugging 1 Debugger Definition A program used to control the execution of another program for diagnostic purposes. Debugger Features / Operations Single-Stepping 100011101010101010

More information

Chronodat Issue Tracker Add-in. User Manual CHRONODAT, LLC. February 15, 2017 Version P age

Chronodat Issue Tracker Add-in. User Manual CHRONODAT, LLC. February 15, 2017 Version P age Chronodat Issue Tracker Add-in User Manual CHRONODAT, LLC February 15, 2017 Version 2.0 1 P age Introduction The introduction section of the document describes the scope and objective of Office 365 Chronodat

More information

Starting Embedded C Programming CM0506 Small Embedded Systems

Starting Embedded C Programming CM0506 Small Embedded Systems Starting Embedded C Programming CM0506 Small Embedded Systems Dr Alun Moon 19th September 2016 This exercise will introduce you to using the development environment to compile, build, downnload, and debug

More information

Chronodat Help Desk. (User Manual) By CHRONODAT, LLC

Chronodat Help Desk. (User Manual) By CHRONODAT, LLC Chronodat Help Desk (User Manual) By CHRONODAT, LLC For further information, visit us at www.chronodat.com For support, contact us at support@chronodat.com Version 2.0.0.0 Created: 09-24-2018 1 P a g e

More information

Developing for Mobile Devices Lab (Part 1 of 2)

Developing for Mobile Devices Lab (Part 1 of 2) Developing for Mobile Devices Lab (Part 1 of 2) Overview Through these two lab sessions you will learn how to create mobile applications for Windows Mobile phones and PDAs. As developing for Windows Mobile

More information

Eclipse CDT Tutorial. Eclipse CDT Homepage: Tutorial written by: James D Aniello

Eclipse CDT Tutorial. Eclipse CDT Homepage:  Tutorial written by: James D Aniello Eclipse CDT Tutorial Eclipse CDT Homepage: http://www.eclipse.org/cdt/ Tutorial written by: James D Aniello Hello and welcome to the Eclipse CDT Tutorial. This tutorial will teach you the basics of the

More information

Object-Oriented Programming in C# (VS 2015)

Object-Oriented Programming in C# (VS 2015) Object-Oriented Programming in C# (VS 2015) This thorough and comprehensive 5-day course is a practical introduction to programming in C#, utilizing the services provided by.net. This course emphasizes

More information

This lesson introduces Blender, covering the tools and concepts necessary to set up a minimal scene in virtual 3D space.

This lesson introduces Blender, covering the tools and concepts necessary to set up a minimal scene in virtual 3D space. 3D Modeling with Blender: 01. Blender Basics Overview This lesson introduces Blender, covering the tools and concepts necessary to set up a minimal scene in virtual 3D space. Concepts Covered Blender s

More information

VB Net Debugging (Console)

VB Net Debugging (Console) VB Net Debugging (Console) Introduction A bug is some sort of error in the code which can prevent your program from running properly. When. you write a substantial program always assume that it contains

More information

string logfilename2 = "c:\\projects\\mygreatapp\\error.log"; static void Main(string[] args) { Console.WriteLine("Your option is: {0}", args[0]);

string logfilename2 = c:\\projects\\mygreatapp\\error.log; static void Main(string[] args) { Console.WriteLine(Your option is: {0}, args[0]); Chapter 1 Page 10 Replace figure 1.2 with the following: Page 16, Para 5 Change "Table 1.2" to "Table 1.3". Chapter 2 Page 44, Code After Para 1 Replace with the following: string logfilename2 = "c:\\projects\\mygreatapp\\error.log";

More information

C# s A Doddle. Steve Love. ACCU April 2013

C# s A Doddle. Steve Love. ACCU April 2013 C# s A Doddle Steve Love ACCU April 2013 A run through C# (pronounced See Sharp ) is a simple, modern, object-oriented, and type-safe programming language. C# has its roots in the C family of languages,

More information

The NetBeans Debugger: A Brief Tutorial

The NetBeans Debugger: A Brief Tutorial The NetBeans Debugger: A Brief Tutorial Based on a tutorial by Anousha Mesbah from the University of Georgia NetBeans provides a debugging tool that lets you trace the execution of a program step by step.

More information

CSCI 161: Introduction to Programming I Lab 1b: Hello, World (Eclipse, Java)

CSCI 161: Introduction to Programming I Lab 1b: Hello, World (Eclipse, Java) Goals - to learn how to compile and execute a Java program - to modify a program to enhance it Overview This activity will introduce you to the Java programming language. You will type in the Java program

More information

COPYRIGHTED MATERIAL. Contents. Part I: C# Fundamentals 1. Chapter 1: The.NET Framework 3. Chapter 2: Getting Started with Visual Studio

COPYRIGHTED MATERIAL. Contents. Part I: C# Fundamentals 1. Chapter 1: The.NET Framework 3. Chapter 2: Getting Started with Visual Studio Introduction XXV Part I: C# Fundamentals 1 Chapter 1: The.NET Framework 3 What s the.net Framework? 3 Common Language Runtime 3.NET Framework Class Library 4 Assemblies and the Microsoft Intermediate Language

More information

CHAPTER 1 COPYRIGHTED MATERIAL. Finding Your Way in the Inventor Interface

CHAPTER 1 COPYRIGHTED MATERIAL. Finding Your Way in the Inventor Interface CHAPTER 1 Finding Your Way in the Inventor Interface COPYRIGHTED MATERIAL Understanding Inventor s interface behavior Opening existing files Creating new files Modifying the look and feel of Inventor Managing

More information

This is the opening view of blender.

This is the opening view of blender. This is the opening view of blender. Note that interacting with Blender is a little different from other programs that you may be used to. For example, left clicking won t select objects on the scene,

More information

Warewolf User Guide 1: Introduction and Basic Concepts

Warewolf User Guide 1: Introduction and Basic Concepts Warewolf User Guide 1: Introduction and Basic Concepts Contents: An Introduction to Warewolf Preparation for the Course Welcome to Warewolf Studio Create your first Microservice Exercise 1 Using the Explorer

More information

[Marco Cantù - Mastering Delphi 2006 Update]

[Marco Cantù - Mastering Delphi 2006 Update] INTRODUCTION This short ebook covers the differences between Delphi 2005 and Delphi 2006. It is meant as an update of the book Mastering Borland Delphi 2006, written by Marco Cantù and published by Sybex

More information

We first learn one useful option of gcc. Copy the following C source file to your

We first learn one useful option of gcc. Copy the following C source file to your Lecture 5 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lab 5: gcc and gdb tools 10-Oct-2018 Location: Teaching Labs Time: Thursday Instructor: Vlado Keselj Lab 5:

More information

Getting started 7. Setting properties 23

Getting started 7. Setting properties 23 Contents 1 2 3 Getting started 7 Introduction 8 Installing Visual Basic 10 Exploring the IDE 12 Starting a new project 14 Adding a visual control 16 Adding functional code 18 Saving projects 20 Reopening

More information

20483BC: Programming in C#

20483BC: Programming in C# 20483BC: Programming in C# Course length: 5 day(s) Course Description The goal of this course is to help students gain essential C# programming skills. This course is an entry point into the Windows Store

More information

Visual Basic 2008 Anne Boehm

Visual Basic 2008 Anne Boehm TRAINING & REFERENCE murach s Visual Basic 2008 Anne Boehm (Chapter 3) Thanks for downloading this chapter from Murach s Visual Basic 2008. We hope it will show you how easy it is to learn from any Murach

More information

COMP327 Mobile Computing Session:

COMP327 Mobile Computing Session: COMP327 Mobile Computing Session: 2018-2019 Lecture Set 5a - + Comments on Lab Work & Assignments [ last updated: 22 October 2018 ] 1 In these Slides... We will cover... Additional Swift 4 features Any

More information

Using Microsoft Excel

Using Microsoft Excel Using Microsoft Excel Excel contains numerous tools that are intended to meet a wide range of requirements. Some of the more specialised tools are useful to people in certain situations while others have

More information

What is the Deal with Color?

What is the Deal with Color? What is the Deal with Color? What is the Deal with Color? Beginning from the beginning Our First Moves Diffuse Object Colors Specular Lighting Transparency Paint on Image Those sliders and things Diffuse

More information

Your First Windows Form

Your First Windows Form Your First Windows Form From now on, we re going to be creating Windows Forms Applications, rather than Console Applications. Windows Forms Applications make use of something called a Form. The Form is

More information

I m sure you have been annoyed at least once by having to type out types like this:

I m sure you have been annoyed at least once by having to type out types like this: Type Inference The first thing I m going to talk about is type inference. C++11 provides mechanisms which make the compiler deduce the types of expressions. These features allow you to make your code more

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

CSE 142 Su 04 Computer Programming 1 - Java. Objects

CSE 142 Su 04 Computer Programming 1 - Java. Objects Objects Objects have state and behavior. State is maintained in instance variables which live as long as the object does. Behavior is implemented in methods, which can be called by other objects to request

More information

Using Microsoft Word. Text Tools. Spell Check

Using Microsoft Word. Text Tools. Spell Check Using Microsoft Word In addition to the editing tools covered in the previous section, Word has a number of other tools to assist in working with test documents. There are tools to help you find and correct

More information

Access Intermediate

Access Intermediate Access 2013 - Intermediate 103-134 Advanced Queries Quick Links Overview Pages AC124 AC125 Selecting Fields Pages AC125 AC128 AC129 AC131 AC238 Sorting Results Pages AC131 AC136 Specifying Criteria Pages

More information

Chronodat Help Desk (Lite)

Chronodat Help Desk (Lite) Chronodat Help Desk (Lite) (User Manual) By CHRONODAT, LLC For further information, visit us at www.chronodat.com For support, contact us at support@chronodat.com Version 2.0.0.0 Created: 10-03-2018 1

More information

IT 374 C# and Applications/ IT695 C# Data Structures

IT 374 C# and Applications/ IT695 C# Data Structures IT 374 C# and Applications/ IT695 C# Data Structures Module 2.1: Introduction to C# App Programming Xianrong (Shawn) Zheng Spring 2017 1 Outline Introduction Creating a Simple App String Interpolation

More information

Lab 7c: Rainfall patterns and drainage density

Lab 7c: Rainfall patterns and drainage density Lab 7c: Rainfall patterns and drainage density This is the third of a four-part handout for class the last two weeks before spring break. Due: Be done with this by class on 11/3. Task: Extract your watersheds

More information