|
Published:
December 26, 2017

C# 7.0 All-in-One For Dummies

Overview

Sharpen your knowledge of C#

C# know-how is a must if you want to be a professional Microsoft developer. It's also good to know a little C# if you're building tools for the web, mobile apps, or other development tasks. C# 7.0 All-in-One For Dummies offers a deep dive into C# for coders still learning the nuances of the valuable programming language. Pop it open to get an intro into coding with C#, how to design secure apps and databases, and even pointers on building web and mobile apps with C#.

C# remains one of the most in-demand programming language skills. The language regularly ranks in the top five among "most in-demand" languages, typically along with Java/JavaScript, C++, and Python. A December 2016 ZDNet article noted 'If your employer is a Microsoft developer, you better know C#." Lucky for you, this approachable, all-in-one guide is here to help you do just that—without ever breaking a sweat!

Includes coverage of the latest changes to C#

  • Shows you exactly what the language can (and can't) do
  • Presents familiar tasks that you can accomplish with C#
  • Provides insight into developing applications that provide protection against hackers

If you have a basic understanding of coding and need to learn C#—or need a reference on the language in order to launch or further your career—look no further.

Read More

About The Author

John Paul Mueller is a writer on programming topics like AWS, Python, Java, HTML, CSS, and JavaScript. William Sempf is a programmer and .NET evangelist. Chuck Sphar was a full-time senior technical writer for the Visual C++ product group at Microsoft.

Sample Chapters

c# 7.0 all-in-one for dummies

CHEAT SHEET

C# provides you with access to a phenomenal array of programming options. Use this cheat sheet to help you get the job done faster and easier when using C# as your development solution of choice.A quick overview of C# 7.0 web application templatesMost developers starting a project today will want to provide web application support, even if the initial application is a desktop application.

HAVE THIS BOOK?

Articles from
the book

Most developers starting a project today will want to provide web application support, even if the initial application is a desktop application. Users no longer want to be tied to the desktop; they want to spread their wings and use devices of every sort anywhere they want to access their data. The following table provides a list of the kinds of web applications you can build using C# 7.
You can define your own custom exception types. Suppose that you want to define a CustomException class. The class might look something like this:public class CustomException : System.Exception{ // Default constructorpublic CustomException() : base(){} // Argument constructorpublic CustomException(String message) : base(message){} // Argument constructor with inner exceptionpublic CustomException(String message, Exception innerException) :base(message, innerException){} // Argument constructor with serialization supportprotected CustomException(SerializationInfo info, StreamingContext context) :base(info, context){}}You can use this basic setup for any custom exception that you want to create.
C# provides you with access to a phenomenal array of programming options. Use this cheat sheet to help you get the job done faster and easier when using C# as your development solution of choice.A quick overview of C# 7.0 web application templatesMost developers starting a project today will want to provide web application support, even if the initial application is a desktop application.
All programming languages rely on keywords, which are words that are reserved and that you can't use for your personal needs. Knowing the keywords enables you to choose other words for your code. For example, you can't create a variable named while because it's a C# keyword. The following table contains the C# keywords.
Touch typists find that using keyboard shortcuts makes them even faster than normal. Of course, you need to know the keyboard shortcuts before you can use them. The following table contains the keyboard shortcuts used most often in Visual Studio 2017. You can find a complete list of keyboard shortcuts online.
When working with a switch statement in C#, the reason for a decision can be quite unclear if you use a numeric value. For example, the following code doesn’t really tell you much about the decision-making process:// Create an ambiguous switch statement.int mySelection = 2;switch (mySelection){case 0:Console.WriteLine("You chose red.
In Visual Studio, and in C#, Visual Basic .NET, and the other .NET languages, one project equals one compiled module — otherwise known as an assembly in .NET. The words module and assembly have somewhat different technical meanings, but only to advanced programmers. Executable or library? Executable (.EXE): A program in its own right that contains a Main() method.
When you define a new variable, you can use the dynamic keyword, and C# will let you make assumptions about the members of the variable. For example, if you want to declare a new Course object, you do it like this:Course newCourse = new Course();newCourse.Schedule();This is, of course, assuming that you have a Course class defined somewhere else in your program, like this:class Course {public void Schedule(){//Something fancy here}}But what if you don't know what class the new object will be?
You can generate static in C# class members. Most data members of a class are specific to their containing object, not to any other objects. Consider the Car class:public class Car{public string licensePlate; // The license plate ID}Because the license plate ID is an object property, it describes each object of class Car uniquely.
Okay, how does C# implement object-oriented programming? In a sense, this is the wrong question. C# is an object-oriented language; however, it doesn’t implement object-oriented programming — the programmer does. You can certainly write a non-object-oriented program in C# or any other language (by, for instance, writing all of Microsoft Word in Main()).
The while loop is the simplest and second most commonly used looping structure in C#. Compared to the for loop, however, the while loop is used about as often as metric tools in an American machine shop.The for loop has this structure:for(initExpression; condition; incrementExpression){// . . . body of code . .
You may decide that you don’t want future generations of programmers to be able to extend a particular class. You can lock the class by using the keyword sealed. A sealed class cannot be used as the base class for any other class. Consider this code snippet: using System;public class BankAccount { // Withdrawal -- You can withdraw any amount up to the // balance; return the amount withdrawn virtual public void Withdraw(decimal withdrawal) { Console.
You’ve no doubt used webster’s or another dictionary, but have you used a C# dictionary? Traditional dictionaries are organized as a bunch of words in alphabetical order. Associated with each word is a body of information including pronunciations, definitions, and other information. To use a dictionary, you look up a word and retrieve its information.
As with prescriptions at your local pharmacy, you can save big by opting for the generic version. Generics, introduced in C# 2.0, are fill-in-the-blanks classes, methods, interfaces, and delegates. For example, the List<T> class defines a generic array-like list that’s quite comparable to the older, nongeneric ArrayList — but better!
C#’s compiler is a handy tool. Often, when you declare a variable with C#, you specify it’s exact data type, like this:int i = 5;string s = "Hello C#";double d = 1.0;You’re allowed to offload some of that work onto the C# compiler, using the var keyword:<strong>var</strong> i = 5;<strong>var</strong> s = "Hello C# 4.
Often an array is the simplest, most straightforward way to deal with a list of Students or a list of doubles. You also encounter many places in the .NET Framework class library that require the use of arrays. But arrays have a couple of fairly serious limitations that sometimes get in your way. At such times, you’ll appreciate the extensive C# repertoire of more flexible collection classes.
Everyone has special needs, and those needs change as time progresses. Microsoft is aware of this. Someone with perfect eyesight in the morning might suffer from tired eyes in the afternoon. Many web users have some sort of special need all the time. Whether the need is intermittent or constant, making your site accessible means making it easy for everyone to use.
C# variables that contain single values are plenty useful. Even class structures that can describe compound objects made up of parts are critical. But you also need a construct for holding a bunch of objects.The built-in class Array is a structure that can contain a series of elements of the same type.Given an array of strings, the following loop averages their lengths:public class Student // Read about classes in Book II.
In versions of C# prior to C# 7.0, every return value was a single object. It could be a really complex object, but it was still a single object. In C# 7.0, you can actually return multiple values using tuples. A tuple is a kind of dynamic array nominally containing two items that you can interpret as a key and value pair (but it isn’t strictly required).
The generics model implemented in C# 2.0 was incomplete. Generics are fine for making the programmer’s life easier, but they did little in that version to make the analyst’s life easier. It used to be very hard to model an actual business model using Generics, and that changed in C# 4.0. Although parameters in C# 2.
Building longer C# strings out of a bunch of shorter strings can cost you an arm and its elbow. Because a string, after it’s created, can’t be changed; it’s immutable. This example doesn’t tack “ly” onto s1:string s1 = “rapid”;string s2 = s1 + “ly”; // s2 = rapidly.It creates a new string composed of the combination.
C# keeps track of whether a variable has been initialized and doesn’t allow you to use an uninitialized variable. For example, the following code chunk generates a compile-time error:public static void Main(string[] args){int n;double d;double calculatedValue = n + d;}C# tracks the fact that the local variables n and d haven’t been assigned a value and doesn’t allow them to be used in the expression.
C# versions prior to 7.0 have certain limits when it comes to throwing an exception as part of an expression. In these previous versions, you essentially had two choices. The first choice was to complete the expression and then check for a result, as shown here:var myStrings = "One,Two,Three".Split(',');var numbers = (myStrings.
After you have the gist of using delegates, take a quick look at Microsoft’s first cut at simplifying delegates in C# 2.0 a couple of years ago. To cut out some of the delegate rigamarole, you can use an anonymous method. Anonymous methods are just written in more traditional notation. Although the syntax and a few details are different, the effect is essentially the same whether you use a raw delegate, an anonymous method, or a lambda expression.
Expression-bodied members first appeared in C# 6.0 as a means to make methods and properties easier to define. In C# 7.0, expression-bodied members also work with constructors, destructors, property accessors, and event accessors. Creating expression-bodied methods The following example shows how you might have created a method before C# 6.
The main reason to work with structures in most code is to create records that contain custom data. You use these custom data records to hold complex information and pass it around as needed within your application. It’s easier and faster to pass a single record than it is to pass a collection of data values, especially when your application performs the task regularly.
Both the integer and floating-point types have their problems in C#. Floating-point variables have rounding problems associated with limits to their accuracy, while int variables just lop off the fractional part of a variable. In some cases, you need a variable type that offers the best of two worlds: Like a floating-point variable, it can store fractions.
You may be interested in whether all the characters (or just one) in a C# string are uppercase or lowercase characters. And you may need to convert from one to the other. Distinguishing between all-uppercase and all-lowercase strings You can use the switch statement to look for a particular string. Normally, you use the switch statement to compare a counting number to some set of possible values; however, switch does work on string objects as well.
https://cdn.prod.website-files.com/6630d85d73068bc09c7c436c/69195ee32d5c606051d9f433_4.%20All%20For%20You.mp3

Frequently Asked Questions

No items found.