Skip to content

Commit

Permalink
Merge pull request dotnet#1383 from dotnet/master
Browse files Browse the repository at this point in the history
Update live with current master
  • Loading branch information
BillWagner authored Jan 4, 2017
2 parents c9e8b05 + 70a8420 commit fca0d61
Show file tree
Hide file tree
Showing 18 changed files with 160 additions and 94 deletions.
Binary file modified _zip/msdn.4.5.2.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions docs/core/tools/project-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: project.json reference
keywords: .NET, .NET Core, project.json
author: aL3891
ms.author: mairaw
ms.date: 09/30/2016
ms.date: 12/21/2016
ms.topic: article
ms.prod: .net-core
ms.technology: dotnet-cli
Expand Down Expand Up @@ -521,7 +521,7 @@ For example:
}
```

This ignores the warnings `The variable 'var' is assigned but its value is never used` and `The variable 'var' is assigned but its value is never used`
This ignores the warnings `The variable 'var' is declared but never used` and `The variable 'var' is assigned but its value is never used`.

### additionalArguments
Type: String[]
Expand Down
2 changes: 1 addition & 1 deletion docs/csharp/csharp-6.md
Original file line number Diff line number Diff line change
Expand Up @@ -577,5 +577,5 @@ a lambda expression as an argument:

[!code-csharp[Lambda](../../samples/snippets/csharp/new-in-6/overloads.cs#Lambda)]

The C# 6 compiler correctly determines that `Task.Run(Func<Task>()` is
The C# 6 compiler correctly determines that `Task.Run(Func<Task>())` is
a better choice.
84 changes: 42 additions & 42 deletions docs/csharp/csharp-7.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ description: Get an overview of the new features coming in the upcoming version
keywords: C#, .NET, .NET Core, Latest Features, What's New
author: BillWagner
ms.author: wiwagn

ms.date: 10/03/2016
ms.date: 12/21/2016
ms.topic: article
ms.prod: visual-studio-dev-15
ms.technology: devlang-csharp
Expand All @@ -21,8 +20,8 @@ C# 7 adds a number of new features to the C# language:
* [Pattern Matching](#pattern-matching)
* [`ref` locals and returns](#ref-locals-and-returns)
* [Local Functions](#local-functions)
<!-- Not available in Preview 5 * [More expression bodied members](#more-expression-bodied-members) -->
<!-- * [`throw` Expressions](#throw-expressions) -->
* [More expression bodied members](#more-expression-bodied-members)
* [`throw` Expressions](#throw-expressions)
* [Generalized async return types](#generalized-async-return-types)
* [Numeric literal syntax improvements](#numeric-literal-syntax-improvements)

Expand Down Expand Up @@ -52,11 +51,6 @@ typed local variable:

[!code-csharp[OutVarVariableDeclarations](../../samples/snippets/csharp/new-in-7/new-in-7/program.cs#02_OutVarVariableDeclarations "Implicitly typed Out variable")]

<!--
Add a sample at RC that shows how if statements
scope out variables.
-->

* The code is easier to read.
- You declare the out variable where you use it, not on another line above.
* No need to assign an initial value.
Expand Down Expand Up @@ -100,12 +94,12 @@ names to each of the members of the tuple:
The `namedLetters` tuple contains fields referred to as `Alpha` and
`Beta`. In a tuple assignment, you can also specify the names of the fields
on the right hand side of the assignment:
on the right-hand side of the assignment:

[!code-csharp[ImplicitNamedTuple](../../samples/snippets/csharp/new-in-7/new-in-7/program.cs#06_ImplicitNamedTuple "Implicitly named tuple")]

The language allows you to specify names for the fields on both the
left and right hand side of the assignment:
left and right-hand side of the assignment:

[!code-csharp[NamedTupleConflict](../../samples/snippets/csharp/new-in-7/new-in-7/program.cs#07_NamedTupleConflict "Named tuple conflict")]

Expand All @@ -121,7 +115,7 @@ defines the type returned. There is no need for creating a new type.

Creating a tuple is more efficient and more productive.
It is a simpler, lightweight syntax to define a data structure that carries
more than one value. The example method below returns the minimimum and maximum
more than one value. The example method below returns the minimum and maximum
values found in a sequence of integers:

[!code-csharp[TupleReturningMethod](../../samples/snippets/csharp/new-in-7/new-in-7/program.cs#08_TupleReturningMethod "Tuple returning method")]
Expand Down Expand Up @@ -295,7 +289,7 @@ this by using unsafe code and returning a pointer to an `int` in previous versio
Let's walk through a series of changes to demonstrate the ref local feature
and show how to create a method that returns a reference to internal storage.
Along the way, you'll learn the rules of the ref return and ref local feature that
protects you from accidentally mis-using it.
protects you from accidentally misusing it.

Start by modifying the `Find` method declaration so that it returns a `ref int`
instead of a tuple. Then, modify the return statement so it returns the value
Expand Down Expand Up @@ -332,7 +326,7 @@ The second `WriteLine` statement in the example above prints out the value `42`,
not `24`. The variable `valItem` is an `int`, not a `ref int`. The `var`
keyword enables the compiler to specify the type, but will not implicitly
add the `ref` modifier. Instead, the value referred to by the `ref return`
is *copied* to the variable on the left hand side of the assignment. The
is *copied* to the variable on the left-hand side of the assignment. The
variable is not a `ref` local.

In order to get the result you want, you need to add the `ref` modifier
Expand All @@ -347,7 +341,7 @@ modified. The local variable has been declared with the `ref` modifier,
and it will take a `ref` return. You must initialize a `ref` variable when
it is declared, you cannot split the declaration and the initialization.

The C# language has two other rules that protect you from mis-using
The C# language has two other rules that protect you from misusing
the `ref` locals and returns:

* You cannot assign a value to a `ref` variable.
Expand All @@ -374,7 +368,7 @@ outside of the context of the single calling location.
For those designs, *local functions* enable you to declare methods
inside the context of another method. This makes it easier for readers
of the class to see that the local method is only called from the context
in which is it declaraed.
in which is it declared.

There are two very common use cases for local functions: public iterator
methods and public async methods. Both types of methods generate
Expand Down Expand Up @@ -432,57 +426,63 @@ work begins:
> could also be accomplished using *lambda expressions*. Those
> interested can [read more about the differences](local-functions-vs-lambdas.md)
<!--
## More expression bodied members
Not available in Preview 5 yet.
-->

<!--
C# 6 introduced [expression bodied members](csharp-6.md#expression-bodied-function-members)
for member functions, and read-only properties. C# 7 expands the allowed
members that can be implemented as expressions. In C# 7, you can implement
*constructors*, *finalizers*, and `get` and `set` accessors on *properties*
and *indexers*. The following class shows examples of each:

[!code-csharp[ExpressionBodiedMembers](../../samples/snippets/csharp/new-in-7/new-in-7/expressionmembers.cs#36_ExpressionBodiedEverything "new expression bodied members")]

> [!NOTE]
> This example does not need a finalizer, but it is shown
> to demonstrate the syntax. You should not implement a
> finalizer in your class unless it is necessary to release
> unmanaged resources. You should also consider using the
> @System.Runtime.InteropServices.SafeHandle class instead
> of managing unmanaged resources directly.
These new locations for expression bodied members represent
an important milestone for the C# language: These features
were implemented by community members working on the open-source
[Roslyn](https://github.com/dotnet/Roslyn) project.

## Throw expressions

Not available in Preview 5
The decision that `throw` was a statement meant that there
were C# constructs where you could not use it. These
In C#, `throw` has always been a statement. Because `throw` is a statement,
not an expression, there were C# constructs where you could not use it. These
included conditional expressions, null coalescing expressions, and some lambda
expressions. The addition of expression bodied members adds more locations
where `throw` expressions would be useful. C# 7 removes introduces *throw expressions*.
where `throw` expressions would be useful. So that you can write any of these
constructs, C# 7 introduces *throw expressions*.

The syntax is the same as you've always used for `throw` statements. Now,
you can place them in new locations, such as an expression bodied member:
The syntax is the same as you've always used for `throw` statements. The only difference
is that now you can place them in new locations, such as in a conditional expression:

```csharp
// Not implemented exception
```
```csharp
// Implement using ? :
```
[!code-csharp[Throw_ExpressionExample](../../samples/snippets/csharp/new-in-7/new-in-7/throwexpressions.cs#37_Throw_ExpressionExample "conditional throw expressions")]

This features enables using throw expressions in initialization expressions:

```csharp
// new way
```
[!code-csharp[ThrowInInitialization](../../samples/snippets/csharp/new-in-7/new-in-7/throwexpressions.cs#38_ThrowInInitialization "conditional throw expressions")]

Previously, those initializations would need to be in a constructor, with the
throw statements in the body of the constructor:

```csharp
// old way with ctor
```

[!code-csharp[ThrowInConstructor](../../samples/snippets/csharp/new-in-7/new-in-7/throwexpressions.cs#39_ThrowInConstructor "throw statements")]

> [!NOTE]
> Both of the preceding constructs will cause exceptions to be thrown during
> the construction of an object. Those are often difficult to recover from.
> For that reason, designs that throw exceptions during construction are
> discouraged.
-->

## Generalized async return types

Returning a `Task` object from async methods can introduce
peformance bottlenecks in certain paths. `Task` is a reference
performance bottlenecks in certain paths. `Task` is a reference
type, so using it means allocating an object. In cases where a
method declared with the `async` modifier returns a cached result, or
completes synchronously, the extra allocations can become a significant
Expand Down
50 changes: 21 additions & 29 deletions docs/csharp/misc/cs0168.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
---
title: "Compiler Warning (level 3) CS0168 | Microsoft Docs"

ms.date: "2015-07-20"
ms.date: "2016-12-21"
ms.prod: .net


ms.technology:
- "devlang-csharp"

ms.technology: "devlang-csharp"
ms.topic: "article"
f1_keywords:
- "CS0168"
Expand All @@ -19,7 +14,6 @@ ms.assetid: 6f5b7fe3-1e91-462f-8a73-b931327ab3f5
caps.latest.revision: 7
author: "BillWagner"
ms.author: "wiwagn"

translation.priority.ht:
- "de-de"
- "es-es"
Expand All @@ -37,28 +31,26 @@ translation.priority.mt:
- "tr-tr"
---
# Compiler Warning (level 3) CS0168
The variable 'var' is assigned but its value is never used
The compiler warns when a variable is declared but not used.
The variable 'var' is declared but never used

The compiler issues a level-three warning when you declare a variable, but do not use it.

The following sample generates two CS0168 warnings:
The following sample generates a CS0168 warning:

```
```cs
// CS0168.cs
// compile with: /W:3
public class clx
{
public int i;
}
public class clz
{
public static void Main()
{
int j = 0; // CS0168, uncomment the following line
// j++;
clx a; // CS0168, try the following line instead
// clx a = new clx();
}
}
```
public class clx
{
public int i;
}

public class clz
{
public static void Main() {
clx a; // CS0168, the variable 'a' is declared but never used
// try the following line instead
// clx a = new clx(); // this does not generate a warning because the clx constructor must execute.
}
}
```
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
---
title: "Sorry, we don&#39;t have specifics on this C# error | Microsoft Docs"

ms.date: "2015-07-20"
ms.prod: .net


ms.technology:
- "devlang-csharp"

ms.topic: "article"
f1_keywords:
- "CS1583"
Expand Down Expand Up @@ -189,7 +185,6 @@ f1_keywords:
- "CS0011"
- "CS1057"
- "CS0144"
- "CS0168"
- "CS1985"
- "CS0060"
- "CS1643"
Expand Down Expand Up @@ -888,7 +883,6 @@ ms.assetid: 48320e4a-6e17-45a6-9966-88c6ec89bd2f
caps.latest.revision: 15
author: "BillWagner"
ms.author: "wiwagn"

translation.priority.ht:
- "cs-cz"
- "de-de"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ When you define a class or struct, you decide whether it makes sense to create a

5. x.`Equals`(null) returns `false`. However, null.Equals(null) throws an exception; it does not obey rule number two above.

Any struct that you define already has a default implementation of value equality that it inherits from the <xref:System.ValueType?displayProperty=fullName> override of the <xref:System.Object.Equals%28System.Object%29?displayProperty=fullName> method. This implementation uses reflection to examine all the public and non-public fields and properties in the type. Although this implementation produces correct results, it is relatively slow compared to a custom implementation that you write specifically for the type.
Any struct that you define already has a default implementation of value equality that it inherits from the <xref:System.ValueType?displayProperty=fullName> override of the <xref:System.Object.Equals%28System.Object%29?displayProperty=fullName> method. This implementation uses reflection to examine all the fields and properties in the type. Although this implementation produces correct results, it is relatively slow compared to a custom implementation that you write specifically for the type.

The implementation details for value equality are different for classes and structs. However, both classes and structs require the same basic steps for implementing equality:

Expand Down Expand Up @@ -80,10 +80,10 @@ When you define a class or struct, you decide whether it makes sense to create a

[!code-cs[csProgGuideStatements#20](../../../csharp/programming-guide/classes-and-structs/codesnippet/CSharp/how-to-define-value-equality-for-a-type_2.cs)]

For structs, the default implementation of <xref:System.Object.Equals%28System.Object%29?displayProperty=fullName> (which is the overridden version in <xref:System.ValueType?displayProperty=fullName>) performs a value equality check by using reflection to compare the values of every field in the type. When an implementer overrides the virtual `Equals` method in a stuct, the purpose is to provide a more efficient means of performing the value equality check and optionally to base the comparison on some subset of the struct's field or properties.
For structs, the default implementation of <xref:System.Object.Equals%28System.Object%29?displayProperty=fullName> (which is the overridden version in <xref:System.ValueType?displayProperty=fullName>) performs a value equality check by using reflection to compare the values of every field in the type. When an implementer overrides the virtual `Equals` method in a struct, the purpose is to provide a more efficient means of performing the value equality check and optionally to base the comparison on some subset of the struct's field or properties.

The [==](../../../csharp/language-reference/operators/equality-comparison-operator.md) and [!=](../../../csharp/language-reference/operators/not-equal-operator.md) operators cannot operate on a struct unless the struct explicitly overloads them.

## See Also
[Equality Comparisons](../../../csharp/programming-guide/statements-expressions-operators/equality-comparisons.md)
[C# Programming Guide](../../../csharp/programming-guide/index.md)
[C# Programming Guide](../../../csharp/programming-guide/index.md)
2 changes: 1 addition & 1 deletion docs/csharp/tour-of-csharp/classes-and-objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: New to C#? Read this overview of classes, objects and inheritance
keywords: .NET, csharp, class, instance, object, inheritance, polymorphism
author: BillWagner
ms.author: wiwagn
ms.date: 2016/08/10
ms.date: 08/10/2016
ms.topic: article
ms.prod: .net
ms.technology: devlang-csharp
Expand Down
2 changes: 1 addition & 1 deletion docs/csharp/tour-of-csharp/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: expressions, operands, and operators are building blocks of the C#
keywords: .NET, csharp, expression, operator, operand
author: BillWagner
ms.author: wiwagn
ms.date: 2016/11/06
ms.date: 11/06/2016
ms.topic: article
ms.prod: .net
ms.technology: devlang-csharp
Expand Down
2 changes: 1 addition & 1 deletion docs/csharp/tour-of-csharp/interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Interfaces define contracts implemented by types in C#
keywords: .NET, csharp, interfaces, multiple inheritance, polymorphism
author: BillWagner
ms.author: wiwagn
ms.date: 2016/08/10
ms.date: 08/10/2016
ms.topic: article
ms.prod: .net
ms.technology: devlang-csharp
Expand Down
2 changes: 1 addition & 1 deletion docs/csharp/tour-of-csharp/statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: You create the actions of a C# program using statements
keywords: .NET, csharp, statements, syntax
author: BillWagner
ms.author: wiwagn
ms.date: 2016/11/06
ms.date: 11/06/2016
ms.topic: article
ms.prod: .net
ms.technology: devlang-csharp
Expand Down
2 changes: 1 addition & 1 deletion docs/csharp/tour-of-csharp/structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Learn the basics of C# value types, called structs
keywords: .NET, C#, struct, value type
author: BillWagner
ms.author: wiwagn
ms.date: 2016/08/10
ms.date: 08/10/2016
ms.topic: article
ms.prod: .net
ms.technology: devlang-csharp
Expand Down
4 changes: 2 additions & 2 deletions docs/fsharp/language-reference/generics/constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ There are several different constraints you can apply to limit the types that ca
|----------|------|-----------|
|Type Constraint|*type-parameter* :&gt; *type*|The provided type must be equal to or derived from the type specified, or, if the type is an interface, the provided type must implement the interface.|
|Null Constraint|*type-parameter* : null|The provided type must support the null literal. This includes all .NET object types but not F# list, tuple, function, class, record, or union types.|
|Explicit Member Constraint|[(]*type-parameter* [or ... or *type-parameter*)] : (*member-signature *)|At least one of the type arguments provided must have a member that has the specified signature; not intended for common use.|
|Explicit Member Constraint|[(]*type-parameter* [or ... or *type-parameter*)] : (*member-signature *)|At least one of the type arguments provided must have a member that has the specified signature; not intended for common use. Members must be either explicitly defined on the type or part of an implicit type extension to be valid targets for an Explicit Member Constraint.|
|Constructor Constraint|*type-parameter* : ( new : unit -&gt; 'a )|The provided type must have a default constructor.|
|Value Type Constraint|: struct|The provided type must be a .NET value type.|
|Reference Type Constraint|: not struct|The provided type must be a .NET reference type.|
Expand Down Expand Up @@ -120,4 +120,4 @@ class end
## See Also
[Generics](index.md)

[Constraints](constraints.md)
[Constraints](constraints.md)
Loading

0 comments on commit fca0d61

Please sign in to comment.