... the StepbyStep for Developers series available from Microsoft Press, such as Microsoft ASP .NET Stepby Step, Microsoft ADO .NET Stepby Step, and Microsoft Windows Communication Foundation Step ... Introducing MicrosoftVisual C# and MicrosoftVisual Studio 2012 MicrosoftVisual C# is Microsoft s powerful component-oriented language C# plays an important role in the architecture of the MicrosoftNET ... Interfaces project to factor common functionality for shape objects into abstract classes Chapter 14 GarbageCollectionDemo This project shows how to implement exception-safe disposal of resources by...
... Introducing MicrosoftVisual C# and MicrosoftVisual Studio 2010 17 On the Build menu, click Build Solution, and verify that the project builds successfully 18 On the Debug menu, click Start ... I Introducing MicrosoftVisual C# and MicrosoftVisual Studio 2010 Data type Description Size (bits) Range Sample usage string Sequence of characters 16 bits per character Not applicable string ... sbyte unchecked case extern long sealed unsafe catch false namespace short ushort char finally new sizeof using checked fixed null stackalloc virtual class float object static void const for operator...
... digitCode = '0' + nextDigit; char digit = Convert.ToChar(digitCode); 102 Part I Introducing MicrosoftVisual C# and MicrosoftVisual Studio 2010 current = digit + current; steps.Text += current ... invoked this code, as described earlier in this section Catching Multiple Exceptions The exception-catching mechanism provided by C# and the MicrosoftNET Framework is quite comprehensive The NET Framework ... recommended The exception object passed in to the catch handler can contain useful information concerning the exception, which is not accessible when using this version of the catch construct...
... instance is created You access the NumCircles field by specifying the Circle class rather than a Circle object For example: Console.WriteLine("Number of Circle objects: {0}", Circle.NumCircles); ... c as a Circle (the name of a class) is very different When you declare c as a Circle, c can refer to a Circle object If you declare refc as another Circle, it can also refer to a Circle object ... new Circle object is created: class Circle { private int radius; public static int NumCircles = 0; public Circle() // default constructor { radius = 0; NumCircles++; } } public Circle(int initialRadius)...
... reference type, you will have two references to the same object For example: Circle c = new Circle(42); Circle refc = c; Declare a variable that can hold a value type or the null value Declare ... enumeration Start MicrosoftVisual Studio 2010 if it is not already running Open the StructsAndEnums project, located in the \Microsoft Press \Visual CSharp StepBy Step\ Chapter 9\StructsAndEnums folder ... randomCardSelector to shuffle the cards before they are dealt to each hand class Pack { public const int NumSuits = 4; public const int CardsPerSuit = 13; private PlayingCard[,] cardPack; private...
... mouseLocation = e.GetPosition(this.drawingCanvas); Circle myCircle = new Circle(100); if (myCircle is IDraw) { IDraw drawCircle = myCircle; drawCircle.SetLocation((int)mouseLocation.X, (int)mouseLocation.Y); ... (int)mouseLocation.Y); drawCircle.Draw(drawingCanvas); } } if (myCircle is IColor) { IColor colorCircle = myCircle; colorCircle.SetColor(Colors.HotPink); } On the Debug menu, click Start Without Debugging ... objects according to the collating sequence of the computer, and if the collection holds numeric objects such as integers, the collection should sort the objects numerically When you define the collection...
... Encapsulate logical array-like access to an object by using indexers n Control read access to indexers by declaring get accessors n Control write access to indexers by declaring set accessors n Create ... declaring get accessors n Control write access to properties by declaring set accessors n Create interfaces that declare properties n Implement interfaces containing properties by using structures ... locY fields Replace the existing constructor with the following code, which calls the constructor in the base class Notice that the body of this constructor is empty because the base class constructor...
... through the IComparer interface to compare two objects, like this: Object x = ; Object y = ; ObjectComparer comparer = new ObjectComparer(); IComparer objectComparator = objectComparer; ... foreach (var companiesPerCountry in companiesGroupedByCountry) { Console.WriteLine("Country: {0}\t{1} companies", companiesPerCountry.Key, companiesPerCountry.Count()); foreach (var companies in companiesPerCountry) ... companiesPerCountry in companiesGroupedByCountry) { Console.WriteLine("Country: {0}\t{1} companies", companiesPerCountry.Key, companiesPerCountry.Count()); foreach (var companies in companiesPerCountry)...
... Location field specify the location Microsoft Press \Visual CSharp StepBy Step\ Chapter 22 under your Documents folder, and then click Save The new project is created and contains a blank form called ... object by returning a new instance of the Complex class by using the constructor you created in the previous step class Complex { public static implicit operator Complex(int from) { return new Complex(from); ... running Open the ComplexNumbers project, located in the \Microsoft Press \Visual CSharp StepBy Step\ Chapter 21\ComplexNumbers folder in your Documents folder This is a console application that you...
... member.IsCaptain = isCaptain.IsChecked.Value; member.MemberSince = memberSince.SelectedDate.Value; member.Methods = new List(); foreach (CheckBox cb in methods.Items) { if (cb.IsChecked.Value) ... folder Microsoft Press \Visual CSharp StepBy Step\ Chapter 23 under your Documents folder In the drop-down list box adjacent to the File name text box, select All Files (*.*) Select the files Face.bmp, ... writer.WriteLine("Captain: {0}", isCaptain.IsChecked.ToString()); writer.WriteLine("Member Since: {0}", memberSince.Text); writer.WriteLine("Methods: "); foreach (CheckBox cb in methods.Items) { if (cb.IsChecked.Value)...
... type, which creates a SqlConnection object: static void Main(string[] args) { SqlConnection dataConnection = new SqlConnection(); } SqlConnection is a subclass of an ADO .NET class called Connection ... the \Microsoft Press \Visual CSharp StepBy Step\ Chapter 25 folder under your Documents folder Replace Name with your user name cd "\Users\Name\Documents \Microsoft Press \Visual CSharp StepBy Step\ Chapter ... \Microsoft Press \Visual CSharp StepBy Step\ Chapter 26 folder under your Documents folder Replace Name with your user name cd "\Users\Name\Documents \Microsoft Press \Visual CSharp StepBy Step\ Chapter...
... pessimistic concurrency Instead, it provides a middle ground Each item in an EntityObject class has a property called Concurrency Mode By default, the Concurrency Mode is set to None, but you can change ... of two users changing the same data is small (hence the term optimistic concurrency.) The opposite of optimistic concurrency is pessimistic concurrency In this scheme, all data is locked in the ... undone, although the changes still remain in the cache in your application When an OptimisticConcurrencyException exception arises, you can determine which entity caused the conflict by examining the...
... OperationCanceledException catch handler runs CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = cancellationTokenSource.Token; ... each of these classes can take an optional CancellationToken parameter, retrieved from a CancellationTokenSource object If you call the Cancel method of the CancellationTokenSource object, each ... can achieve synchronized access is to lock data Locking Data The C# language provides locking semantics through the lock keyword, which you can use to guarantee exclusive access to resources You...
... the MicrosoftNET Framework With MicrosoftVisual Studio 2010, you can build Web services by using MicrosoftVisual C+ +, MicrosoftVisual C# , or MicrosoftVisual Basic However, as far as a client ... MyCollection, // and wrap it in a BlockingCollection object MyCollection intCollection = new MyCollection(); BlockingCollection collection = new BlockingCollection(myCo ... namespace (ConcurrentBag, ConcurrentDictionary, ConcurrentQueue, or ConcurrentStack) or create your own class that implements the IProducerConsumerCollection interface and...
... Introducing MicrosoftVisual C# and MicrosoftVisual Studio 2010 In the Location field, if you are using Windows Vista type C: \Users\YourName\ Documents \Microsoft Press \Visual CSharp StepBy Step\ Chapter ... or contact Microsoft Press International directly at fax (425) 936-7329 Visit our Web site at www .microsoft. com/mspress Send comments to mspinput @microsoft. com Microsoft, Microsoft Press, Excel, ... offered through the above address Microsoft Visual C# 2010 StepbyStep Part I Introducing MicrosoftVisual C# and MicrosoftVisual Studio 2010 In this part: Welcome to C# ...
... to Microsoft Press \Visual CSharp StepBy Step\ Chapter under your Documents folder, and then click Save Chapter Welcome to C# 19 In the New Project dialog box, click the WPF Application icon ... C: \Users\YourName\Documents \Microsoft Press \Visual CSharp StepBy Step\ Chapter If you are using Microsoft Windows XP or Windows Server 2003, type C: \Documents and Settings\YourName\My Documents \Microsoft Press \Visual ... menu, click New Project In the New Project dialog box, click the Console Application icon In the Name field, type TextHello Click OK Chapter Welcome to C# Visual Studio creates the project using...
... click Step Into or On the Debug menu, click Step Into Step out of a method On the Debug toolbar, click Step Out or On the Debug menu, click Step Out Chapter Using Decision Statements After completing ... the contents of an unassigned variable, your program will not compile 67 68 Part I Introducing MicrosoftVisual C# and MicrosoftVisual Studio 2008 MicrosoftVisual C# provides a data type called ... Selection project, located in the \Microsoft Press \Visual CSharp Stepby Step\ Chapter 4\Selection folder in your Documents folder On the Debug menu, click Start Without Debugging Visual Studio...