diff --git a/docs/core/porting/libraries.md b/docs/core/porting/libraries.md index c96b55c89a5bb..236cfbeaea96f 100644 --- a/docs/core/porting/libraries.md +++ b/docs/core/porting/libraries.md @@ -67,18 +67,6 @@ Similar to CAS, Security Transparency allows separating sandboxed code from secu Use security boundaries provided by the operating system, such as virtualization, containers, or user accounts for running processes with the least set of privileges. -### global.json - -The *global.json* file is an optional file that allows you to set the .NET Core tools version of a project. If you're using nightly builds of .NET Core and wish to specify a specific version of the SDK, specify the version with a *global.json* file. It typically resides in the current working directory or one of its parent directories. - -```json -{ - "sdk": { - "version": "2.1.0-preview1-006491" - } -} -``` - ## Converting a PCL project You can convert the targets of a PCL project to .NET Standard by loading the library in Visual Studio 2017 and performing the following steps: diff --git a/docs/csharp/language-reference/keywords/byte.md b/docs/csharp/language-reference/keywords/byte.md index 05cb1f8ebd38a..2ef07e1b12642 100644 --- a/docs/csharp/language-reference/keywords/byte.md +++ b/docs/csharp/language-reference/keywords/byte.md @@ -12,7 +12,7 @@ ms.assetid: 111f1db9-ca32-4f0e-b497-4783517eda47 `byte` denotes an integral type that stores values as indicated in the following table. -|Type|Range|Size|.NET Framework type| +|Type|Range|Size|.NET type| |----------|-----------|----------|-------------------------| |`byte`|0 to 255|Unsigned 8-bit integer|| diff --git a/docs/csharp/language-reference/keywords/char.md b/docs/csharp/language-reference/keywords/char.md index 28ca9b53041ca..7648e7d4df72f 100644 --- a/docs/csharp/language-reference/keywords/char.md +++ b/docs/csharp/language-reference/keywords/char.md @@ -14,7 +14,7 @@ The `char` keyword is used to declare an instance of the | diff --git a/docs/csharp/language-reference/keywords/codesnippet/CSharp/enum_1.cs b/docs/csharp/language-reference/keywords/codesnippet/CSharp/enum_1.cs deleted file mode 100644 index 3b9b0921153fe..0000000000000 --- a/docs/csharp/language-reference/keywords/codesnippet/CSharp/enum_1.cs +++ /dev/null @@ -1,17 +0,0 @@ - - public class EnumTest - { - enum Day { Sun, Mon, Tue, Wed, Thu, Fri, Sat }; - - static void Main() - { - int x = (int)Day.Sun; - int y = (int)Day.Fri; - Console.WriteLine("Sun = {0}", x); - Console.WriteLine("Fri = {0}", y); - } - } - /* Output: - Sun = 0 - Fri = 5 - */ diff --git a/docs/csharp/language-reference/keywords/codesnippet/CSharp/enum_2.cs b/docs/csharp/language-reference/keywords/codesnippet/CSharp/enum_2.cs deleted file mode 100644 index fc145ef3865a2..0000000000000 --- a/docs/csharp/language-reference/keywords/codesnippet/CSharp/enum_2.cs +++ /dev/null @@ -1,15 +0,0 @@ - public class EnumTest2 - { - enum Range : long { Max = 2147483648L, Min = 255L }; - static void Main() - { - long x = (long)Range.Max; - long y = (long)Range.Min; - Console.WriteLine("Max = {0}", x); - Console.WriteLine("Min = {0}", y); - } - } - /* Output: - Max = 2147483648 - Min = 255 - */ \ No newline at end of file diff --git a/docs/csharp/language-reference/keywords/codesnippet/CSharp/enum_3.cs b/docs/csharp/language-reference/keywords/codesnippet/CSharp/enum_3.cs deleted file mode 100644 index 677905612b0a8..0000000000000 --- a/docs/csharp/language-reference/keywords/codesnippet/CSharp/enum_3.cs +++ /dev/null @@ -1,33 +0,0 @@ - // Add the attribute Flags or FlagsAttribute. - [Flags] - public enum CarOptions - { - // The flag for SunRoof is 0001. - SunRoof = 0x01, - // The flag for Spoiler is 0010. - Spoiler = 0x02, - // The flag for FogLights is 0100. - FogLights = 0x04, - // The flag for TintedWindows is 1000. - TintedWindows = 0x08, - } - - class FlagTest - { - static void Main() - { - // The bitwise OR of 0001 and 0100 is 0101. - CarOptions options = CarOptions.SunRoof | CarOptions.FogLights; - - // Because the Flags attribute is specified, Console.WriteLine displays - // the name of each enum element that corresponds to a flag that has - // the value 1 in variable options. - Console.WriteLine(options); - // The integer value of 0101 is 5. - Console.WriteLine((int)options); - } - } - /* Output: - SunRoof, FogLights - 5 - */ \ No newline at end of file diff --git a/docs/csharp/language-reference/keywords/codesnippet/CSharp/equals_1.cs b/docs/csharp/language-reference/keywords/codesnippet/CSharp/equals_1.cs deleted file mode 100644 index 1c0998777fe95..0000000000000 --- a/docs/csharp/language-reference/keywords/codesnippet/CSharp/equals_1.cs +++ /dev/null @@ -1,4 +0,0 @@ - var innerJoinQuery = - from category in categories - join prod in products on category.ID equals prod.CategoryID - select new { ProductName = prod.Name, Category = category.Name }; \ No newline at end of file diff --git a/docs/csharp/language-reference/keywords/codesnippet/CSharp/explicit_1.cs b/docs/csharp/language-reference/keywords/codesnippet/CSharp/explicit_1.cs deleted file mode 100644 index 20b47c03eaab8..0000000000000 --- a/docs/csharp/language-reference/keywords/codesnippet/CSharp/explicit_1.cs +++ /dev/null @@ -1,5 +0,0 @@ - // Must be defined inside a class called Fahrenheit: - public static explicit operator Celsius(Fahrenheit fahr) - { - return new Celsius((5.0f / 9.0f) * (fahr.degrees - 32)); - } \ No newline at end of file diff --git a/docs/csharp/language-reference/keywords/codesnippet/CSharp/explicit_2.cs b/docs/csharp/language-reference/keywords/codesnippet/CSharp/explicit_2.cs deleted file mode 100644 index 2e1a0f066f852..0000000000000 --- a/docs/csharp/language-reference/keywords/codesnippet/CSharp/explicit_2.cs +++ /dev/null @@ -1,3 +0,0 @@ - Fahrenheit fahr = new Fahrenheit(100.0f); - Console.Write("{0} Fahrenheit", fahr.Degrees); - Celsius c = (Celsius)fahr; \ No newline at end of file diff --git a/docs/csharp/language-reference/keywords/codesnippet/CSharp/explicit_3.cs b/docs/csharp/language-reference/keywords/codesnippet/CSharp/explicit_3.cs deleted file mode 100644 index d882e87e5789d..0000000000000 --- a/docs/csharp/language-reference/keywords/codesnippet/CSharp/explicit_3.cs +++ /dev/null @@ -1,51 +0,0 @@ - - class Celsius - { - public Celsius(float temp) - { - degrees = temp; - } - public static explicit operator Fahrenheit(Celsius c) - { - return new Fahrenheit((9.0f / 5.0f) * c.degrees + 32); - } - public float Degrees - { - get { return degrees; } - } - private float degrees; - } - - class Fahrenheit - { - public Fahrenheit(float temp) - { - degrees = temp; - } - // Must be defined inside a class called Fahrenheit: - public static explicit operator Celsius(Fahrenheit fahr) - { - return new Celsius((5.0f / 9.0f) * (fahr.degrees - 32)); - } - public float Degrees - { - get { return degrees; } - } - private float degrees; - } - - class MainClass - { - static void Main() - { - Fahrenheit fahr = new Fahrenheit(100.0f); - Console.Write("{0} Fahrenheit", fahr.Degrees); - Celsius c = (Celsius)fahr; - - Console.Write(" = {0} Celsius", c.Degrees); - Fahrenheit fahr2 = (Fahrenheit)c; - Console.WriteLine(" = {0} Fahrenheit", fahr2.Degrees); - } - } - // Output: - // 100 Fahrenheit = 37.77778 Celsius = 100 Fahrenheit \ No newline at end of file diff --git a/docs/csharp/language-reference/keywords/codesnippet/CSharp/explicit_4.cs b/docs/csharp/language-reference/keywords/codesnippet/CSharp/explicit_4.cs deleted file mode 100644 index b7fd2fb8be384..0000000000000 --- a/docs/csharp/language-reference/keywords/codesnippet/CSharp/explicit_4.cs +++ /dev/null @@ -1,40 +0,0 @@ - struct Digit - { - byte value; - public Digit(byte value) - { - if (value > 9) - { - throw new ArgumentException(); - } - this.value = value; - } - - // Define explicit byte-to-Digit conversion operator: - public static explicit operator Digit(byte b) - { - Digit d = new Digit(b); - Console.WriteLine("conversion occurred"); - return d; - } - } - - class ExplicitTest - { - static void Main() - { - try - { - byte b = 3; - Digit d = (Digit)b; // explicit conversion - } - catch (Exception e) - { - Console.WriteLine("{0} Exception caught.", e); - } - } - } - /* - Output: - conversion occurred - */ \ No newline at end of file diff --git a/docs/csharp/language-reference/keywords/codesnippet/CSharp/extern_1.cs b/docs/csharp/language-reference/keywords/codesnippet/CSharp/extern_1.cs deleted file mode 100644 index 4d130733c68ff..0000000000000 --- a/docs/csharp/language-reference/keywords/codesnippet/CSharp/extern_1.cs +++ /dev/null @@ -1,15 +0,0 @@ - //using System.Runtime.InteropServices; - class ExternTest - { - [DllImport("User32.dll", CharSet=CharSet.Unicode)] - public static extern int MessageBox(IntPtr h, string m, string c, int type); - - static int Main() - { - string myString; - Console.Write("Enter your message: "); - myString = Console.ReadLine(); - return MessageBox((IntPtr)0, myString, "My Message Box", 0); - } - - } diff --git a/docs/csharp/language-reference/keywords/codesnippet/CSharp/false-literal_1.cs b/docs/csharp/language-reference/keywords/codesnippet/CSharp/false-literal_1.cs deleted file mode 100644 index d5081754f68dd..0000000000000 --- a/docs/csharp/language-reference/keywords/codesnippet/CSharp/false-literal_1.cs +++ /dev/null @@ -1,10 +0,0 @@ - - class TestClass - { - static void Main() - { - bool a = false; - Console.WriteLine( a ? "yes" : "no" ); - } - } - // Output: no diff --git a/docs/csharp/language-reference/keywords/codesnippet/CSharp/false-operator_1.cs b/docs/csharp/language-reference/keywords/codesnippet/CSharp/false-operator_1.cs deleted file mode 100644 index dcf15c2da45af..0000000000000 --- a/docs/csharp/language-reference/keywords/codesnippet/CSharp/false-operator_1.cs +++ /dev/null @@ -1,93 +0,0 @@ - // For example purposes only. Use the built-in nullable bool - // type (bool?) whenever possible. - public struct DBBool - { - // The three possible DBBool values. - public static readonly DBBool Null = new DBBool(0); - public static readonly DBBool False = new DBBool(-1); - public static readonly DBBool True = new DBBool(1); - // Private field that stores –1, 0, 1 for False, Null, True. - sbyte value; - // Private instance constructor. The value parameter must be –1, 0, or 1. - DBBool(int value) - { - this.value = (sbyte)value; - } - // Properties to examine the value of a DBBool. Return true if this - // DBBool has the given value, false otherwise. - public bool IsNull { get { return value == 0; } } - public bool IsFalse { get { return value < 0; } } - public bool IsTrue { get { return value > 0; } } - // Implicit conversion from bool to DBBool. Maps true to DBBool.True and - // false to DBBool.False. - public static implicit operator DBBool(bool x) - { - return x ? True : False; - } - // Explicit conversion from DBBool to bool. Throws an exception if the - // given DBBool is Null; otherwise returns true or false. - public static explicit operator bool(DBBool x) - { - if (x.value == 0) throw new InvalidOperationException(); - return x.value > 0; - } - // Equality operator. Returns Null if either operand is Null; otherwise - // returns True or False. - public static DBBool operator ==(DBBool x, DBBool y) - { - if (x.value == 0 || y.value == 0) return Null; - return x.value == y.value ? True : False; - } - // Inequality operator. Returns Null if either operand is Null; otherwise - // returns True or False. - public static DBBool operator !=(DBBool x, DBBool y) - { - if (x.value == 0 || y.value == 0) return Null; - return x.value != y.value ? True : False; - } - // Logical negation operator. Returns True if the operand is False, Null - // if the operand is Null, or False if the operand is True. - public static DBBool operator !(DBBool x) - { - return new DBBool(-x.value); - } - // Logical AND operator. Returns False if either operand is False, - // Null if either operand is Null, otherwise True. - public static DBBool operator &(DBBool x, DBBool y) - { - return new DBBool(x.value < y.value ? x.value : y.value); - } - // Logical OR operator. Returns True if either operand is True, - // Null if either operand is Null, otherwise False. - public static DBBool operator |(DBBool x, DBBool y) - { - return new DBBool(x.value > y.value ? x.value : y.value); - } - // Definitely true operator. Returns true if the operand is True, false - // otherwise. - public static bool operator true(DBBool x) - { - return x.value > 0; - } - // Definitely false operator. Returns true if the operand is False, false - // otherwise. - public static bool operator false(DBBool x) - { - return x.value < 0; - } - public override bool Equals(object obj) - { - if (!(obj is DBBool)) return false; - return value == ((DBBool)obj).value; - } - public override int GetHashCode() - { - return value; - } - public override string ToString() - { - if (value > 0) return "DBBool.True"; - if (value < 0) return "DBBool.False"; - return "DBBool.Null"; - } - } \ No newline at end of file diff --git a/docs/csharp/language-reference/keywords/codesnippet/CSharp/float_1.cs b/docs/csharp/language-reference/keywords/codesnippet/CSharp/float_1.cs deleted file mode 100644 index cb6ab8e2a93da..0000000000000 --- a/docs/csharp/language-reference/keywords/codesnippet/CSharp/float_1.cs +++ /dev/null @@ -1,17 +0,0 @@ - class FloatTest - { - static void Main() - { - int x = 3; - float y = 4.5f; - short z = 5; - var result = x * y / z; - Console.WriteLine("The result is {0}", result); - Type type = result.GetType(); - Console.WriteLine("result is of type {0}", type.ToString()); - } - } - /* Output: - The result is 2.7 - result is of type System.Single //'float' is alias for 'Single' - */ \ No newline at end of file diff --git a/docs/csharp/language-reference/keywords/codesnippet/CSharp/from-clause_1.cs b/docs/csharp/language-reference/keywords/codesnippet/CSharp/from-clause_1.cs deleted file mode 100644 index 89121aeeb3e28..0000000000000 --- a/docs/csharp/language-reference/keywords/codesnippet/CSharp/from-clause_1.cs +++ /dev/null @@ -1,21 +0,0 @@ - class LowNums - { - static void Main() - { - // A simple data source. - int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; - - // Create the query. - // lowNums is an IEnumerable - var lowNums = from num in numbers - where num < 5 - select num; - - // Execute the query. - foreach (int i in lowNums) - { - Console.Write(i + " "); - } - } - } - // Output: 4 1 3 2 0 \ No newline at end of file diff --git a/docs/csharp/language-reference/keywords/codesnippet/CSharp/from-clause_2.cs b/docs/csharp/language-reference/keywords/codesnippet/CSharp/from-clause_2.cs deleted file mode 100644 index f6df5c1d1246a..0000000000000 --- a/docs/csharp/language-reference/keywords/codesnippet/CSharp/from-clause_2.cs +++ /dev/null @@ -1,55 +0,0 @@ - class CompoundFrom - { - // The element type of the data source. - public class Student - { - public string LastName { get; set; } - public List Scores {get; set;} - } - - static void Main() - { - - // Use a collection initializer to create the data source. Note that - // each element in the list contains an inner sequence of scores. - List students = new List - { - new Student {LastName="Omelchenko", Scores= new List {97, 72, 81, 60}}, - new Student {LastName="O'Donnell", Scores= new List {75, 84, 91, 39}}, - new Student {LastName="Mortensen", Scores= new List {88, 94, 65, 85}}, - new Student {LastName="Garcia", Scores= new List {97, 89, 85, 82}}, - new Student {LastName="Beebe", Scores= new List {35, 72, 91, 70}} - }; - - // Use a compound from to access the inner sequence within each element. - // Note the similarity to a nested foreach statement. - var scoreQuery = from student in students - from score in student.Scores - where score > 90 - select new { Last = student.LastName, score }; - - // Execute the queries. - Console.WriteLine("scoreQuery:"); - // Rest the mouse pointer on scoreQuery in the following line to - // see its type. The type is IEnumerable<'a>, where 'a is an - // anonymous type defined as new {string Last, int score}. That is, - // each instance of this anonymous type has two members, a string - // (Last) and an int (score). - foreach (var student in scoreQuery) - { - Console.WriteLine("{0} Score: {1}", student.Last, student.score); - } - - // Keep the console window open in debug mode. - Console.WriteLine("Press any key to exit."); - Console.ReadKey(); - } - } - /* - scoreQuery: - Omelchenko Score: 97 - O'Donnell Score: 91 - Mortensen Score: 94 - Garcia Score: 97 - Beebe Score: 91 - */ \ No newline at end of file diff --git a/docs/csharp/language-reference/keywords/codesnippet/CSharp/from-clause_3.cs b/docs/csharp/language-reference/keywords/codesnippet/CSharp/from-clause_3.cs deleted file mode 100644 index ef2fda5615dd5..0000000000000 --- a/docs/csharp/language-reference/keywords/codesnippet/CSharp/from-clause_3.cs +++ /dev/null @@ -1,64 +0,0 @@ - class CompoundFrom2 - { - static void Main() - { - char[] upperCase = { 'A', 'B', 'C' }; - char[] lowerCase = { 'x', 'y', 'z' }; - - // The type of joinQuery1 is IEnumerable<'a>, where 'a - // indicates an anonymous type. This anonymous type has two - // members, upper and lower, both of type char. - var joinQuery1 = - from upper in upperCase - from lower in lowerCase - select new { upper, lower }; - - // The type of joinQuery2 is IEnumerable<'a>, where 'a - // indicates an anonymous type. This anonymous type has two - // members, upper and lower, both of type char. - var joinQuery2 = - from lower in lowerCase - where lower != 'x' - from upper in upperCase - select new { lower, upper }; - - - // Execute the queries. - Console.WriteLine("Cross join:"); - // Rest the mouse pointer on joinQuery1 to verify its type. - foreach (var pair in joinQuery1) - { - Console.WriteLine("{0} is matched to {1}", pair.upper, pair.lower); - } - - Console.WriteLine("Filtered non-equijoin:"); - // Rest the mouse pointer over joinQuery2 to verify its type. - foreach (var pair in joinQuery2) - { - Console.WriteLine("{0} is matched to {1}", pair.lower, pair.upper); - } - - // Keep the console window open in debug mode. - Console.WriteLine("Press any key to exit."); - Console.ReadKey(); - } - } - /* Output: - Cross join: - A is matched to x - A is matched to y - A is matched to z - B is matched to x - B is matched to y - B is matched to z - C is matched to x - C is matched to y - C is matched to z - Filtered non-equijoin: - y is matched to A - y is matched to B - y is matched to C - z is matched to A - z is matched to B - z is matched to C - */ \ No newline at end of file diff --git a/docs/csharp/language-reference/keywords/decimal.md b/docs/csharp/language-reference/keywords/decimal.md index 846527d868a75..173d1e6801023 100644 --- a/docs/csharp/language-reference/keywords/decimal.md +++ b/docs/csharp/language-reference/keywords/decimal.md @@ -12,7 +12,7 @@ ms.assetid: b6522132-b5ee-4be3-ad13-3adfdb7de7a1 The `decimal` keyword indicates a 128-bit data type. Compared to other floating-point types, the `decimal` type has more precision and a smaller range, which makes it appropriate for financial and monetary calculations. The approximate range and precision for the `decimal` type are shown in the following table. -|Type|Approximate Range|Precision|.NET Framework type| +|Type|Approximate Range|Precision|.NET type| |----------|-----------------------|---------------|-------------------------| |`decimal`|(-7.9 x 1028 to 7.9 x 1028) / (100 to 1028)|28-29 significant digits|| diff --git a/docs/csharp/language-reference/keywords/double.md b/docs/csharp/language-reference/keywords/double.md index 667292c73c128..68fa41ba527f9 100644 --- a/docs/csharp/language-reference/keywords/double.md +++ b/docs/csharp/language-reference/keywords/double.md @@ -12,7 +12,7 @@ ms.assetid: 0980e11b-6004-4102-abcf-cfc280fc6991 The `double` keyword signifies a simple type that stores 64-bit floating-point values. The following table shows the precision and approximate range for the `double` type. -|Type|Approximate range|Precision|.NET Framework type| +|Type|Approximate range|Precision|.NET type| |----------|-----------------------|---------------|-------------------------| |`double`|±5.0 × 10−324 to ±1.7 × 10308|15-16 digits|| diff --git a/docs/csharp/language-reference/keywords/enum.md b/docs/csharp/language-reference/keywords/enum.md index 3317c9a949e2b..61fa586c6de82 100644 --- a/docs/csharp/language-reference/keywords/enum.md +++ b/docs/csharp/language-reference/keywords/enum.md @@ -1,5 +1,5 @@ --- -title: "enum (C# Reference)" +title: "enum keyword (C# Reference)" ms.date: 07/20/2015 f1_keywords: - "enum" @@ -9,85 +9,93 @@ helpviewer_keywords: ms.assetid: bbeb9a0f-e9b3-41ab-b0a6-c41b1a08974c --- # enum (C# Reference) + The `enum` keyword is used to declare an enumeration, a distinct type that consists of a set of named constants called the enumerator list. - - Usually it is best to define an enum directly within a namespace so that all classes in the namespace can access it with equal convenience. However, an enum can also be nested within a class or struct. - - By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1. For example, in the following enumeration, `Sat` is `0`, `Sun` is `1`, `Mon` is `2`, and so forth. - -```csharp -enum Day {Sat, Sun, Mon, Tue, Wed, Thu, Fri}; -``` - - Enumerators can use initializers to override the default values, as shown in the following example. - -```csharp -enum Day {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri}; -``` - - In this enumeration, the sequence of elements is forced to start from `1` instead of `0`. However, including a constant that has the value of 0 is recommended. For more information, see [Enumeration Types](../../../csharp/programming-guide/enumeration-types.md). - - Every enumeration type has an underlying type, which can be any integral type except [char](../../../csharp/language-reference/keywords/char.md). The default underlying type of enumeration elements is [int](../../../csharp/language-reference/keywords/int.md). To declare an enum of another integral type, such as [byte](../../../csharp/language-reference/keywords/byte.md), use a colon after the identifier followed by the type, as shown in the following example. - -```csharp -enum Day : byte {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri}; -``` - - The approved types for an enum are [byte](../../../csharp/language-reference/keywords/byte.md), [sbyte](../../../csharp/language-reference/keywords/sbyte.md), [short](../../../csharp/language-reference/keywords/short.md), [ushort](../../../csharp/language-reference/keywords/ushort.md), [int](../../../csharp/language-reference/keywords/int.md), [uint](../../../csharp/language-reference/keywords/uint.md), [long](../../../csharp/language-reference/keywords/long.md), or [ulong](../../../csharp/language-reference/keywords/ulong.md). - - A variable of type `Day` can be assigned any value in the range of the underlying type; the values are not limited to the named constants. - - The default value of an `enum E` is the value produced by the expression `(E)0`. - + +Usually it is best to define an enum directly within a namespace so that all classes in the namespace can access it with equal convenience. However, an enum can also be nested within a class or struct. + +By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1. For example, in the following enumeration, `Sat` is `0`, `Sun` is `1`, `Mon` is `2`, and so forth. + +```csharp +enum Day {Sat, Sun, Mon, Tue, Wed, Thu, Fri}; +``` + +Enumerators can use initializers to override the default values, as shown in the following example. + +```csharp +enum Day {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri}; +``` + +In this enumeration, the sequence of elements is forced to start from `1` instead of `0`. However, including a constant that has the value of 0 is recommended. For more information, see [Enumeration Types](../../programming-guide/enumeration-types.md). + +Every enumeration type has an underlying type, which can be any integral type except [char](char.md). The default underlying type of enumeration elements is [int](int.md). To declare an enum of another integral type, such as [byte](byte.md), use a colon after the identifier followed by the type, as shown in the following example. + +```csharp +enum Day : byte {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri}; +``` + +The approved types for an enum are [byte](byte.md), [sbyte](sbyte.md), [short](short.md), [ushort](ushort.md), [int](int.md), [uint](uint.md), [long](long.md), or [ulong](ulong.md). + +A variable of type `Day` can be assigned any value in the range of the underlying type; the values are not limited to the named constants. + +The default value of an `enum E` is the value produced by the expression `(E)0`. + > [!NOTE] -> An enumerator cannot contain white space in its name. - - The underlying type specifies how much storage is allocated for each enumerator. However, an explicit cast is necessary to convert from `enum` type to an integral type. For example, the following statement assigns the enumerator `Sun` to a variable of the type [int](../../../csharp/language-reference/keywords/int.md) by using a cast to convert from `enum` to `int`. - -```csharp -int x = (int)Day.Sun; -``` - - When you apply to an enumeration that contains elements that can be combined with a bitwise `OR` operation, the attribute affects the behavior of the `enum` when it is used with some tools. You can notice these changes when you use tools such as the class methods and the Expression Evaluator. (See the third example.) - -## Robust Programming - Just as with any constant, all references to the individual values of an enum are converted to numeric literals at compile time. This can create potential versioning issues as described in [Constants](../../../csharp/programming-guide/classes-and-structs/constants.md). - - Assigning additional values to new versions of enums, or changing the values of the enum members in a new version, can cause problems for dependent source code. Enum values often are used in [switch](../../../csharp/language-reference/keywords/switch.md) statements. If additional elements have been added to the `enum` type, the default section of the switch statement can be selected unexpectedly. - - If other developers use your code, you should provide guidelines about how their code should react if new elements are added to any `enum` types. - -## Example - In the following example, an enumeration, `Day`, is declared. Two enumerators are explicitly converted to integer and assigned to integer variables. - - [!code-csharp[csrefKeywordsTypes#10](../../../csharp/language-reference/keywords/codesnippet/CSharp/enum_1.cs)] - -## Example - In the following example, the base-type option is used to declare an `enum` whose members are of type `long`. Notice that even though the underlying type of the enumeration is `long`, the enumeration members still must be explicitly converted to type `long` by using a cast. - - [!code-csharp[csrefKeywordsTypes#11](../../../csharp/language-reference/keywords/codesnippet/CSharp/enum_2.cs)] - -## Example - The following code example illustrates the use and effect of the attribute on an `enum` declaration. - - [!code-csharp[csrefKeywordsTypes#12](../../../csharp/language-reference/keywords/codesnippet/CSharp/enum_3.cs)] - -## Comments - If you remove `Flags`, the example displays the following values: - - `5` - - `5` - -## C# Language Specification - [!INCLUDE[CSharplangspec](~/includes/csharplangspec-md.md)] - -## See Also - [C# Reference](../../../csharp/language-reference/index.md) - [Enumeration Types](../../../csharp/programming-guide/enumeration-types.md) - [C# Keywords](../../../csharp/language-reference/keywords/index.md) - [Integral Types Table](../../../csharp/language-reference/keywords/integral-types-table.md) - [Built-In Types Table](../../../csharp/language-reference/keywords/built-in-types-table.md) - [Implicit Numeric Conversions Table](../../../csharp/language-reference/keywords/implicit-numeric-conversions-table.md) - [Explicit Numeric Conversions Table](../../../csharp/language-reference/keywords/explicit-numeric-conversions-table.md) - [Enum Naming Conventions](https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces#naming-enumerations) +> An enumerator cannot contain white space in its name. + +The underlying type specifies how much storage is allocated for each enumerator. However, an explicit cast is necessary to convert from `enum` type to an integral type. For example, the following statement assigns the enumerator `Sun` to a variable of the type [int](int.md) by using a cast to convert from `enum` to `int`. + +```csharp +int x = (int)Day.Sun; +``` + +When you apply to an enumeration that contains elements that can be combined with a bitwise `OR` operation, the attribute affects the behavior of the `enum` when it is used with some tools. You can notice these changes when you use tools such as the class methods and the Expression Evaluator. (See the third example.) + +## Robust programming + +Just as with any constant, all references to the individual values of an enum are converted to numeric literals at compile time. This can create potential versioning issues as described in [Constants](../../programming-guide/classes-and-structs/constants.md). + +Assigning additional values to new versions of enums, or changing the values of the enum members in a new version, can cause problems for dependent source code. Enum values often are used in [switch](switch.md) statements. If additional elements have been added to the `enum` type, the default section of the switch statement can be selected unexpectedly. + +If other developers use your code, you should provide guidelines about how their code should react if new elements are added to any `enum` types. + +## Example + +In the following example, an enumeration, `Day`, is declared. Two enumerators are explicitly converted to integer and assigned to integer variables. + +[!code-csharp[csrefKeywordsTypes#10](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csrefKeywordsTypes/CS/keywordsTypes.cs#10)] + +## Example + +In the following example, the base-type option is used to declare an `enum` whose members are of type `long`. Notice that even though the underlying type of the enumeration is `long`, the enumeration members still must be explicitly converted to type `long` by using a cast. + +[!code-csharp[csrefKeywordsTypes#11](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csrefKeywordsTypes/CS/keywordsTypes.cs#11)] + +## Example + +The following code example illustrates the use and effect of the attribute on an `enum` declaration. + +[!code-csharp[csrefKeywordsTypes#12](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csrefKeywordsTypes/CS/keywordsTypes.cs#12)] + +## Comments + +If you remove `Flags`, the example displays the following values: + +`5` + +`5` + +## C# language specification + +[!INCLUDE[CSharplangspec](~/includes/csharplangspec-md.md)] + +## See also + +[C# Reference](../index.md) +[Enumeration Types](../../programming-guide/enumeration-types.md) +[C# Keywords](index.md) +[Integral Types Table](integral-types-table.md) +[Built-In Types Table](built-in-types-table.md) +[Implicit Numeric Conversions Table](implicit-numeric-conversions-table.md) +[Explicit Numeric Conversions Table](explicit-numeric-conversions-table.md) +[Enum Naming Conventions](../../../standard/design-guidelines/names-of-classes-structs-and-interfaces.md#naming-enumerations) diff --git a/docs/csharp/language-reference/keywords/equals.md b/docs/csharp/language-reference/keywords/equals.md index 6a1f36b80dc1d..60ca43da16b86 100644 --- a/docs/csharp/language-reference/keywords/equals.md +++ b/docs/csharp/language-reference/keywords/equals.md @@ -1,5 +1,5 @@ --- -title: "equals (C# Reference)" +title: "equals contextual keyword (C# Reference)" ms.date: 07/20/2015 f1_keywords: - "equals_CSharpKeyword" @@ -9,12 +9,15 @@ helpviewer_keywords: ms.assetid: e981309a-e4bf-444c-8a2b-5c695e6114b1 --- # equals (C# Reference) -The `equals` contextual keyword is used in a `join` clause in a query expression to compare the elements of two sequences. For more information, see [join clause](../../../csharp/language-reference/keywords/join-clause.md). - -## Example - The following example shows the use of the `equals` keyword in a `join` clause. - - [!code-csharp[csrefKeywordsContextual#12](../../../csharp/language-reference/keywords/codesnippet/CSharp/equals_1.cs)] - -## See Also - [LINQ Query Expressions](../../../csharp/programming-guide/linq-query-expressions/index.md) + +The `equals` contextual keyword is used in a `join` clause in a query expression to compare the elements of two sequences. For more information, see [join clause](join-clause.md). + +## Example + +The following example shows the use of the `equals` keyword in a `join` clause. + +[!code-csharp[csrefKeywordsContextual#12](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csrefKeywordsContextual/CS/csrefKeywordsContextual.cs#12)] + +## See also + +[Language Integrated Query (LINQ)](../../linq/index.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/keywords/explicit.md b/docs/csharp/language-reference/keywords/explicit.md index b3f43cbb8f50d..78e749133cb66 100644 --- a/docs/csharp/language-reference/keywords/explicit.md +++ b/docs/csharp/language-reference/keywords/explicit.md @@ -1,5 +1,5 @@ --- -title: "explicit (C# Reference)" +title: "explicit keyword (C# Reference)" ms.date: 07/20/2015 f1_keywords: - "explicit_CSharpKeyword" @@ -9,38 +9,43 @@ helpviewer_keywords: ms.assetid: cfb8f42a-e411-4db2-af9b-796b05644846 --- # explicit (C# Reference) -The `explicit` keyword declares a user-defined type conversion operator that must be invoked with a cast. For example, this operator converts from a class called Fahrenheit to a class called Celsius: - - [!code-csharp[csrefKeywordsConversion#2](../../../csharp/language-reference/keywords/codesnippet/CSharp/explicit_1.cs)] - - This conversion operator can be invoked like this: - - [!code-csharp[csrefKeywordsConversion#3](../../../csharp/language-reference/keywords/codesnippet/CSharp/explicit_2.cs)] - - The conversion operator converts from a source type to a target type. The source type provides the conversion operator. Unlike implicit conversion, explicit conversion operators must be invoked by means of a cast. If a conversion operation can cause exceptions or lose information, you should mark it `explicit`. This prevents the compiler from silently invoking the conversion operation with possibly unforeseen consequences. - - Omitting the cast results in compile-time error CS0266. - - For more information, see [Using Conversion Operators](../../../csharp/programming-guide/statements-expressions-operators/using-conversion-operators.md). - -## Example - The following example provides a `Fahrenheit` and a `Celsius` class, each of which provides an explicit conversion operator to the other class. - - [!code-csharp[csrefKeywordsConversion#1](../../../csharp/language-reference/keywords/codesnippet/CSharp/explicit_3.cs)] - -## Example - The following example defines a struct, `Digit`, that represents a single decimal digit. An operator is defined for conversions from `byte` to `Digit`, but because not all bytes can be converted to a `Digit`, the conversion is explicit. - - [!code-csharp[csrefKeywordsConversion#4](../../../csharp/language-reference/keywords/codesnippet/CSharp/explicit_4.cs)] - -## C# Language Specification - [!INCLUDE[CSharplangspec](~/includes/csharplangspec-md.md)] - -## See Also - [C# Reference](../../../csharp/language-reference/index.md) - [C# Programming Guide](../../../csharp/programming-guide/index.md) - [C# Keywords](../../../csharp/language-reference/keywords/index.md) - [implicit](../../../csharp/language-reference/keywords/implicit.md) - [operator (C# Reference)](../../../csharp/language-reference/keywords/operator.md) - [How to: Implement User-Defined Conversions Between Structs](../../../csharp/programming-guide/statements-expressions-operators/how-to-implement-user-defined-conversions-between-structs.md) - [Chained user-defined explicit conversions in C#](https://blogs.msdn.microsoft.com/ericlippert/2007/04/16/chained-user-defined-explicit-conversions-in-c/) + +The `explicit` keyword declares a user-defined type conversion operator that must be invoked with a cast. For example, this operator converts from a class called Fahrenheit to a class called Celsius: + +[!code-csharp[csrefKeywordsConversion#2](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csrefKeywordsConversion/CS/csrefKeywordsConversion.cs#2)] + +This conversion operator can be invoked like this: + +[!code-csharp[csrefKeywordsConversion#3](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csrefKeywordsConversion/CS/csrefKeywordsConversion.cs#3)] + +The conversion operator converts from a source type to a target type. The source type provides the conversion operator. Unlike implicit conversion, explicit conversion operators must be invoked by means of a cast. If a conversion operation can cause exceptions or lose information, you should mark it `explicit`. This prevents the compiler from silently invoking the conversion operation with possibly unforeseen consequences. + +Omitting the cast results in compile-time error CS0266. + +For more information, see [Using Conversion Operators](../../programming-guide/statements-expressions-operators/using-conversion-operators.md). + +## Example + +The following example provides a `Fahrenheit` and a `Celsius` class, each of which provides an explicit conversion operator to the other class. + +[!code-csharp[csrefKeywordsConversion#1](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csrefKeywordsConversion/CS/csrefKeywordsConversion.cs#1)] + +## Example + +The following example defines a struct, `Digit`, that represents a single decimal digit. An operator is defined for conversions from `byte` to `Digit`, but because not all bytes can be converted to a `Digit`, the conversion is explicit. + +[!code-csharp[csrefKeywordsConversion#4](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csrefKeywordsConversion/CS/csrefKeywordsConversion.cs#4)] + +## C# language specification + +[!INCLUDE[CSharplangspec](~/includes/csharplangspec-md.md)] + +## See also + +[C# Reference](../index.md) +[C# Programming Guide](../../programming-guide/index.md) +[C# Keywords](index.md) +[implicit](implicit.md) +[operator (C# Reference)](operator.md) +[How to: Implement User-Defined Conversions Between Structs](../../programming-guide/statements-expressions-operators/how-to-implement-user-defined-conversions-between-structs.md) +[Chained user-defined explicit conversions in C#](https://blogs.msdn.microsoft.com/ericlippert/2007/04/16/chained-user-defined-explicit-conversions-in-c/) \ No newline at end of file diff --git a/docs/csharp/language-reference/keywords/extern.md b/docs/csharp/language-reference/keywords/extern.md index 5529a895fe134..42a5b9067dd25 100644 --- a/docs/csharp/language-reference/keywords/extern.md +++ b/docs/csharp/language-reference/keywords/extern.md @@ -1,5 +1,5 @@ --- -title: "extern (C# Reference)" +title: "extern modifier (C# Reference)" ms.date: 07/20/2015 f1_keywords: - "extern_CSharpKeyword" @@ -10,80 +10,83 @@ helpviewer_keywords: ms.assetid: 9c3f02c4-51b8-4d80-9cb2-f2b6e1ae15c7 --- # extern (C# Reference) -The `extern` modifier is used to declare a method that is implemented externally. A common use of the `extern` modifier is with the `DllImport` attribute when you are using Interop services to call into unmanaged code. In this case, the method must also be declared as `static`, as shown in the following example: - -```csharp -[DllImport("avifil32.dll")] -private static extern void AVIFileInit(); -``` - - The `extern` keyword can also define an external assembly alias, which makes it possible to reference different versions of the same component from within a single assembly. For more information, see [extern alias](../../../csharp/language-reference/keywords/extern-alias.md). - - It is an error to use the [abstract](../../../csharp/language-reference/keywords/abstract.md) and `extern` modifiers together to modify the same member. Using the `extern` modifier means that the method is implemented outside the C# code, whereas using the `abstract` modifier means that the method implementation is not provided in the class. - - The extern keyword has more limited uses in C# than in C++. To compare the C# keyword with the C++ keyword, see Using extern to Specify Linkage in the C++ Language Reference. - -## Example - **Example 1.** In this example, the program receives a string from the user and displays it inside a message box. The program uses the `MessageBox` method imported from the User32.dll library. - - [!code-csharp[csrefKeywordsModifiers#8](../../../csharp/language-reference/keywords/codesnippet/CSharp/extern_1.cs)] - -## Example - **Example 2.** This example illustrates a C# program that calls into a C library (a native DLL). - - 1. Create the following C file and name it `cmdll.c`: - -``` -// cmdll.c -// Compile with: /LD -int __declspec(dllexport) SampleMethod(int i) -{ - return i*10; -} -``` - -## Example - 2. Open a Visual Studio x64 (or x32) Native Tools Command Prompt window from the Visual Studio installation directory and compile the `cmdll.c` file by typing **cl /LD cmdll.c** at the command prompt. - - 3. In the same directory, create the following C# file and name it `cm.cs`: - -```csharp -// cm.cs -using System; -using System.Runtime.InteropServices; -public class MainClass -{ - [DllImport("Cmdll.dll")] - public static extern int SampleMethod(int x); - - static void Main() - { - Console.WriteLine("SampleMethod() returns {0}.", SampleMethod(5)); - } -} -``` - -## Example - 3. Open a Visual Studio x64 (or x32) Native Tools Command Prompt window from the Visual Studio installation directory and compile the `cm.cs` file by typing: - -> **csc cm.cs** (for the x64 command prompt) -> —or— -> **csc /platform:x86 cm.cs** (for the x32 command prompt) - - This will create the executable file `cm.exe`. - - 4. Run `cm.exe`. The `SampleMethod` method passes the value 5 to the DLL file, which returns the value multiplied by 10. The program produces the following output: - -``` -SampleMethod() returns 50. -``` - -## C# Language Specification - [!INCLUDE[CSharplangspec](~/includes/csharplangspec-md.md)] - -## See Also - - [C# Reference](../../../csharp/language-reference/index.md) - [C# Programming Guide](../../../csharp/programming-guide/index.md) - [C# Keywords](../../../csharp/language-reference/keywords/index.md) - [Modifiers](../../../csharp/language-reference/keywords/modifiers.md) + +The `extern` modifier is used to declare a method that is implemented externally. A common use of the `extern` modifier is with the `DllImport` attribute when you are using Interop services to call into unmanaged code. In this case, the method must also be declared as `static`, as shown in the following example: + +```csharp +[DllImport("avifil32.dll")] +private static extern void AVIFileInit(); +``` + +The `extern` keyword can also define an external assembly alias, which makes it possible to reference different versions of the same component from within a single assembly. For more information, see [extern alias](extern-alias.md). + +It is an error to use the [abstract](abstract.md) and `extern` modifiers together to modify the same member. Using the `extern` modifier means that the method is implemented outside the C# code, whereas using the `abstract` modifier means that the method implementation is not provided in the class. + +The extern keyword has more limited uses in C# than in C++. To compare the C# keyword with the C++ keyword, see Using extern to Specify Linkage in the C++ Language Reference. + +## Example 1 + +In this example, the program receives a string from the user and displays it inside a message box. The program uses the `MessageBox` method imported from the User32.dll library. + +[!code-csharp[csrefKeywordsModifiers#8](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csrefKeywordsModifiers/CS/csrefKeywordsModifiers.cs#8)] + +## Example 2 + +This example illustrates a C# program that calls into a C library (a native DLL). + +1. Create the following C file and name it `cmdll.c`: + +```c +// cmdll.c +// Compile with: -LD +int __declspec(dllexport) SampleMethod(int i) +{ + return i*10; +} +``` + +2. Open a Visual Studio x64 (or x32) Native Tools Command Prompt window from the Visual Studio installation directory and compile the `cmdll.c` file by typing **cl -LD cmdll.c** at the command prompt. + +3. In the same directory, create the following C# file and name it `cm.cs`: + +```csharp +// cm.cs +using System; +using System.Runtime.InteropServices; +public class MainClass +{ + [DllImport("Cmdll.dll")] + public static extern int SampleMethod(int x); + + static void Main() + { + Console.WriteLine("SampleMethod() returns {0}.", SampleMethod(5)); + } +} +``` + +4. Open a Visual Studio x64 (or x32) Native Tools Command Prompt window from the Visual Studio installation directory and compile the `cm.cs` file by typing: + +> **csc cm.cs** (for the x64 command prompt) +> —or— +> **csc -platform:x86 cm.cs** (for the x32 command prompt) + +This will create the executable file `cm.exe`. + +5. Run `cm.exe`. The `SampleMethod` method passes the value 5 to the DLL file, which returns the value multiplied by 10. The program produces the following output: + +``` +SampleMethod() returns 50. +``` + +## C# language specification + +[!INCLUDE[CSharplangspec](~/includes/csharplangspec-md.md)] + +## See also + + +[C# Reference](../index.md) +[C# Programming Guide](../../programming-guide/index.md) +[C# Keywords](index.md) +[Modifiers](modifiers.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/keywords/false-literal.md b/docs/csharp/language-reference/keywords/false-literal.md index c5092a7dfd4f2..eee5fb49b85a6 100644 --- a/docs/csharp/language-reference/keywords/false-literal.md +++ b/docs/csharp/language-reference/keywords/false-literal.md @@ -1,21 +1,25 @@ --- -title: "false Literal (C# Reference)" +title: "false literal (C# Reference)" ms.date: 07/20/2015 helpviewer_keywords: - "false literal keyword [C#]" ms.assetid: fcc1c1a5-0e42-4226-a128-81492a9bf719 --- -# false Literal (C# Reference) -Represents the boolean value false. - -## Example - [!code-csharp[csrefKeywordsOperator#3](../../../csharp/language-reference/keywords/codesnippet/CSharp/false-literal_1.cs)] - -## C# Language Specification - [!INCLUDE[CSharplangspec](~/includes/csharplangspec-md.md)] - -## See Also - [C# Reference](../../../csharp/language-reference/index.md) - [C# Programming Guide](../../../csharp/programming-guide/index.md) - [C# Keywords](../../../csharp/language-reference/keywords/index.md) - [true](../../../csharp/language-reference/keywords/true.md) +# false literal (C# Reference) + +Represents the boolean value false. + +## Example + +[!code-csharp[csrefKeywordsOperator#3](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csrefKeywordsOperator/CS/csrefKeywordsOperators.cs#3)] + +## C# language specification + +[!INCLUDE[CSharplangspec](~/includes/csharplangspec-md.md)] + +## See also + +[C# Reference](../index.md) +[C# Programming Guide](../../programming-guide/index.md) +[C# Keywords](index.md) +[true](true.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/keywords/false-operator.md b/docs/csharp/language-reference/keywords/false-operator.md index c88ed16ba8aef..07188e851899d 100644 --- a/docs/csharp/language-reference/keywords/false-operator.md +++ b/docs/csharp/language-reference/keywords/false-operator.md @@ -1,31 +1,34 @@ --- -title: "false Operator (C# Reference)" +title: "false operator (C# Reference)" ms.date: 07/20/2015 helpviewer_keywords: - "false operator keyword [C#]" ms.assetid: 81a888fd-011e-4589-b242-6c261fea505e --- -# false Operator (C# Reference) -Returns the [bool](../../../csharp/language-reference/keywords/bool.md) value `true` to indicate that an operand is `false` and returns `false` otherwise. - - Prior to C# 2.0, the `true` and `false` operators were used to create user-defined nullable value types that were compatible with types such as `SqlBool`. However, the language now provides built-in support for nullable value types, and whenever possible you should use those instead of overloading the `true` and `false` operators. For more information, see [Nullable Types](../../../csharp/programming-guide/nullable-types/index.md). - - With nullable Booleans, the expression `a != b` is not necessarily equal to `!(a == b)` because one or both of the values might be null. You have to overload both the `true` and `false` operators separately to correctly handle the null values in the expression. The following example shows how to overload and use the `true` and `false` operators. - - [!code-csharp[csrefKeywordsOperator#16](../../../csharp/language-reference/keywords/codesnippet/CSharp/false-operator_1.cs)] - - A type that overloads the `true` and `false` operators can be used for the controlling expression in [if](../../../csharp/language-reference/keywords/if-else.md), [do](../../../csharp/language-reference/keywords/do.md), [while](../../../csharp/language-reference/keywords/while.md), and [for](../../../csharp/language-reference/keywords/for.md) statements and in [conditional expressions](../../../csharp/language-reference/operators/conditional-operator.md). - - If a type defines operator `false`, it must also define operator [true](../../../csharp/language-reference/keywords/true.md). - - A type cannot directly overload the conditional logical operators [&&](../../../csharp/language-reference/operators/conditional-and-operator.md) and [||](../../../csharp/language-reference/operators/conditional-or-operator.md), but an equivalent effect can be achieved by overloading the regular logical operators and operators `true` and `false`. - -## C# Language Specification - [!INCLUDE[CSharplangspec](~/includes/csharplangspec-md.md)] - -## See Also - [C# Reference](../../../csharp/language-reference/index.md) - [C# Programming Guide](../../../csharp/programming-guide/index.md) - [C# Keywords](../../../csharp/language-reference/keywords/index.md) - [C# Operators](../../../csharp/language-reference/operators/index.md) - [true](../../../csharp/language-reference/keywords/true.md) +# false operator (C# Reference) + +Returns the [bool](bool.md) value `true` to indicate that an operand is `false` and returns `false` otherwise. + +Prior to C# 2.0, the `true` and `false` operators were used to create user-defined nullable value types that were compatible with types such as `SqlBool`. However, the language now provides built-in support for nullable value types, and whenever possible you should use those instead of overloading the `true` and `false` operators. For more information, see [Nullable Types](../../programming-guide/nullable-types/index.md). + +With nullable Booleans, the expression `a != b` is not necessarily equal to `!(a == b)` because one or both of the values might be null. You have to overload both the `true` and `false` operators separately to correctly handle the null values in the expression. The following example shows how to overload and use the `true` and `false` operators. + +[!code-csharp[csrefKeywordsOperator#16](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csrefKeywordsOperator/CS/csrefKeywordsOperators.cs#16)] + +A type that overloads the `true` and `false` operators can be used for the controlling expression in [if](if-else.md), [do](do.md), [while](while.md), and [for](for.md) statements and in [conditional expressions](../operators/conditional-operator.md). + +If a type defines operator `false`, it must also define operator [true](true.md). + +A type cannot directly overload the conditional logical operators [&&](../operators/conditional-and-operator.md) and [||](../operators/conditional-or-operator.md), but an equivalent effect can be achieved by overloading the regular logical operators and operators `true` and `false`. + +## C# language specification + +[!INCLUDE[CSharplangspec](~/includes/csharplangspec-md.md)] + +## See also + +[C# Reference](../index.md) +[C# Programming Guide](../../programming-guide/index.md) +[C# Keywords](index.md) +[C# Operators](../operators/index.md) +[true](true.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/keywords/float.md b/docs/csharp/language-reference/keywords/float.md index 5d115d81cf487..9c84e23fb55e9 100644 --- a/docs/csharp/language-reference/keywords/float.md +++ b/docs/csharp/language-reference/keywords/float.md @@ -1,5 +1,5 @@ --- -title: "float (C# Reference)" +title: "float keyword (C# Reference)" ms.date: 07/20/2015 f1_keywords: - "float" @@ -10,55 +10,61 @@ helpviewer_keywords: ms.assetid: 1e77db7b-dedb-48b7-8dd1-b055e96a9258 --- # float (C# Reference) -The `float` keyword signifies a simple type that stores 32-bit floating-point values. The following table shows the precision and approximate range for the `float` type. - -|Type|Approximate range|Precision|.NET Framework type| + +The `float` keyword signifies a simple type that stores 32-bit floating-point values. The following table shows the precision and approximate range for the `float` type. + +|Type|Approximate range|Precision|.NET type| |----------|-----------------------|---------------|-------------------------| -|`float`|-3.4 × 1038to +3.4 × 1038|7 digits|| - -## Literals - By default, a real numeric literal on the right side of the assignment operator is treated as [double](double.md). Therefore, to initialize a float variable, use the suffix `f` or `F`, as in the following example: - +|`float`|-3.4 × 1038 to +3.4 × 1038|7 digits|| + +## Literals + +By default, a real numeric literal on the right side of the assignment operator is treated as [double](double.md). Therefore, to initialize a float variable, use the suffix `f` or `F`, as in the following example: + ```csharp -float x = 3.5F; +float x = 3.5F; ``` - - If you do not use the suffix in the previous declaration, you will get a compilation error because you are trying to store a [double](double.md) value into a `float` variable. - -## Conversions - You can mix numeric integral types and floating-point types in an expression. In this case, the integral types are converted to floating-point types. The evaluation of the expression is performed according to the following rules: - -- If one of the floating-point types is [double](double.md), the expression evaluates to [double](double.md) or [bool](bool.md) in relational or Boolean expressions. - -- If there is no [double](double.md) type in the expression, the expression evaluates to `float` or [bool](bool.md) in relational or Boolean expressions. - - A floating-point expression can contain the following sets of values: - -- Positive and negative zero - -- Positive and negative infinity - -- Not-a-Number value (NaN) - -- The finite set of nonzero values - - For more information about these values, see IEEE Standard for Binary Floating-Point Arithmetic, available on the [IEEE](http://www.ieee.org) Web site. - -## Example - In the following example, an [int](int.md), a [short](short.md), and a `float` are included in a mathematical expression giving a `float` result. (Remember that `float` is an alias for the type.) Notice that there is no [double](double.md) in the expression. - - [!code-csharp[csrefKeywordsTypes#13](../../../csharp/language-reference/keywords/codesnippet/CSharp/float_1.cs)] - -## C# Language Specification - [!INCLUDE[CSharplangspec](~/includes/csharplangspec-md.md)] - -## See Also - - [C# Reference](../../../csharp/language-reference/index.md) - [C# Programming Guide](../../../csharp/programming-guide/index.md) - [Casting and Type Conversions](../../../csharp/programming-guide/types/casting-and-type-conversions.md) - [C# Keywords](index.md) - [Integral Types Table](integral-types-table.md) - [Built-In Types Table](built-in-types-table.md) - [Implicit Numeric Conversions Table](implicit-numeric-conversions-table.md) - [Explicit Numeric Conversions Table](explicit-numeric-conversions-table.md) + +If you do not use the suffix in the previous declaration, you will get a compilation error because you are trying to store a [double](double.md) value into a `float` variable. + +## Conversions + +You can mix numeric integral types and floating-point types in an expression. In this case, the integral types are converted to floating-point types. The evaluation of the expression is performed according to the following rules: + +- If one of the floating-point types is [double](double.md), the expression evaluates to [double](double.md) or [bool](bool.md) in relational or Boolean expressions. + +- If there is no [double](double.md) type in the expression, the expression evaluates to `float` or [bool](bool.md) in relational or Boolean expressions. + +A floating-point expression can contain the following sets of values: + +- Positive and negative zero + +- Positive and negative infinity + +- Not-a-Number value (NaN) + +- The finite set of nonzero values + +For more information about these values, see IEEE Standard for Binary Floating-Point Arithmetic, available on the [IEEE](http://www.ieee.org) website. + +## Example + +In the following example, an [int](int.md), a [short](short.md), and a `float` are included in a mathematical expression giving a `float` result. (Remember that `float` is an alias for the type.) Notice that there is no [double](double.md) in the expression. + +[!code-csharp[csrefKeywordsTypes#13](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csrefKeywordsTypes/CS/keywordsTypes.cs#13)] + +## C# language specification + +[!INCLUDE[CSharplangspec](~/includes/csharplangspec-md.md)] + +## See also + + +[C# Reference](../index.md) +[C# Programming Guide](../../programming-guide/index.md) +[Casting and Type Conversions](../../programming-guide/types/casting-and-type-conversions.md) +[C# Keywords](index.md) +[Integral Types Table](integral-types-table.md) +[Built-In Types Table](built-in-types-table.md) +[Implicit Numeric Conversions Table](implicit-numeric-conversions-table.md) +[Explicit Numeric Conversions Table](explicit-numeric-conversions-table.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/keywords/from-clause.md b/docs/csharp/language-reference/keywords/from-clause.md index 4a2891718f75c..5be58462ad806 100644 --- a/docs/csharp/language-reference/keywords/from-clause.md +++ b/docs/csharp/language-reference/keywords/from-clause.md @@ -10,39 +10,44 @@ helpviewer_keywords: ms.assetid: 1aefd18c-1314-47f8-99ec-9bcefb09e699 --- # from clause (C# Reference) -A query expression must begin with a `from` clause. Additionally, a query expression can contain sub-queries, which also begin with a `from` clause. The `from` clause specifies the following: - -- The data source on which the query or sub-query will be run. - -- A local *range variable* that represents each element in the source sequence. - - Both the range variable and the data source are strongly typed. The data source referenced in the `from` clause must have a type of , , or a derived type such as . - - In the following example, `numbers` is the data source and `num` is the range variable. Note that both variables are strongly typed even through the [var](../../../csharp/language-reference/keywords/var.md) keyword is used. - - [!code-csharp[cscsrefQueryKeywords#1](../../../csharp/language-reference/keywords/codesnippet/CSharp/from-clause_1.cs)] - -## The Range Variable - The compiler infers the type of the range variable when the data source implements . For example, if the source has a type of `IEnumerable`, then the range variable is inferred to be `Customer`. The only time that you must specify the type explicitly is when the source is a non-generic `IEnumerable` type such as . For more information, see [How to: Query an ArrayList with LINQ](../../programming-guide/concepts/linq/how-to-query-an-arraylist-with-linq.md). - - In the previous example `num` is inferred to be of type `int`. Because the range variable is strongly typed, you can call methods on it or use it in other operations. For example, instead of writing `select num`, you could write `select num.ToString()` to cause the query expression to return a sequence of strings instead of integers. Or you could write `select n + 10` to cause the expression to return the sequence 14, 11, 13, 12, 10. For more information, see [select clause](../../../csharp/language-reference/keywords/select-clause.md). - - The range variable is like an iteration variable in a [foreach](../../../csharp/language-reference/keywords/foreach-in.md) statement except for one very important difference: a range variable never actually stores data from the source. It just a syntactic convenience that enables the query to describe what will occur when the query is executed. For more information, see [Introduction to LINQ Queries (C#)](../../../csharp/programming-guide/concepts/linq/introduction-to-linq-queries.md). - -## Compound from Clauses - In some cases, each element in the source sequence may itself be either a sequence or contain a sequence. For example, your data source may be an `IEnumerable` where each student object in the sequence contains a list of test scores. To access the inner list within each `Student` element, you can use compound `from` clauses. The technique is like using nested [foreach](../../../csharp/language-reference/keywords/foreach-in.md) statements. You can add [where](../../../csharp/language-reference/keywords/partial-method.md) or [orderby](../../../csharp/language-reference/keywords/orderby-clause.md) clauses to either `from` clause to filter the results. The following example shows a sequence of `Student` objects, each of which contains an inner `List` of integers representing test scores. To access the inner list, use a compound `from` clause. You can insert clauses between the two `from` clauses if necessary. - - [!code-csharp[cscsrefQueryKeywords#2](../../../csharp/language-reference/keywords/codesnippet/CSharp/from-clause_2.cs)] - -## Using Multiple from Clauses to Perform Joins - A compound `from` clause is used to access inner collections in a single data source. However, a query can also contain multiple `from` clauses that generate supplemental queries from independent data sources. This technique enables you to perform certain types of join operations that are not possible by using the [join clause](../../../csharp/language-reference/keywords/join-clause.md). - - The following example shows how two `from` clauses can be used to form a complete cross join of two data sources. - - [!code-csharp[cscsrefQueryKeywords#3](../../../csharp/language-reference/keywords/codesnippet/CSharp/from-clause_3.cs)] - - For more information about join operations that use multiple `from` clauses, see [How to: Perform Custom Join Operations](../../../csharp/programming-guide/linq-query-expressions/how-to-perform-custom-join-operations.md). - -## See Also - [Query Keywords (LINQ)](../../../csharp/language-reference/keywords/query-keywords.md) - [LINQ Query Expressions](../../../csharp/programming-guide/linq-query-expressions/index.md) + +A query expression must begin with a `from` clause. Additionally, a query expression can contain sub-queries, which also begin with a `from` clause. The `from` clause specifies the following: + +- The data source on which the query or sub-query will be run. + +- A local *range variable* that represents each element in the source sequence. + +Both the range variable and the data source are strongly typed. The data source referenced in the `from` clause must have a type of , , or a derived type such as . + +In the following example, `numbers` is the data source and `num` is the range variable. Note that both variables are strongly typed even through the [var](var.md) keyword is used. + +[!code-csharp[cscsrefQueryKeywords#1](~/samples/snippets/csharp/VS_Snippets_VBCSharp/CsCsrefQueryKeywords/CS/From.cs#1)] + +## The range variable + +The compiler infers the type of the range variable when the data source implements . For example, if the source has a type of `IEnumerable`, then the range variable is inferred to be `Customer`. The only time that you must specify the type explicitly is when the source is a non-generic `IEnumerable` type such as . For more information, see [How to: Query an ArrayList with LINQ](../../programming-guide/concepts/linq/how-to-query-an-arraylist-with-linq.md). + +In the previous example `num` is inferred to be of type `int`. Because the range variable is strongly typed, you can call methods on it or use it in other operations. For example, instead of writing `select num`, you could write `select num.ToString()` to cause the query expression to return a sequence of strings instead of integers. Or you could write `select n + 10` to cause the expression to return the sequence 14, 11, 13, 12, 10. For more information, see [select clause](select-clause.md). + +The range variable is like an iteration variable in a [foreach](foreach-in.md) statement except for one very important difference: a range variable never actually stores data from the source. It just a syntactic convenience that enables the query to describe what will occur when the query is executed. For more information, see [Introduction to LINQ Queries (C#)](../../programming-guide/concepts/linq/introduction-to-linq-queries.md). + +## Compound from clauses + +In some cases, each element in the source sequence may itself be either a sequence or contain a sequence. For example, your data source may be an `IEnumerable` where each student object in the sequence contains a list of test scores. To access the inner list within each `Student` element, you can use compound `from` clauses. The technique is like using nested [foreach](foreach-in.md) statements. You can add [where](partial-method.md) or [orderby](orderby-clause.md) clauses to either `from` clause to filter the results. The following example shows a sequence of `Student` objects, each of which contains an inner `List` of integers representing test scores. To access the inner list, use a compound `from` clause. You can insert clauses between the two `from` clauses if necessary. + +[!code-csharp[cscsrefQueryKeywords#2](~/samples/snippets/csharp/VS_Snippets_VBCSharp/CsCsrefQueryKeywords/CS/From.cs#2)] + +## Using Multiple from Clauses to Perform Joins + +A compound `from` clause is used to access inner collections in a single data source. However, a query can also contain multiple `from` clauses that generate supplemental queries from independent data sources. This technique enables you to perform certain types of join operations that are not possible by using the [join clause](join-clause.md). + +The following example shows how two `from` clauses can be used to form a complete cross join of two data sources. + +[!code-csharp[cscsrefQueryKeywords#3](~/samples/snippets/csharp/VS_Snippets_VBCSharp/CsCsrefQueryKeywords/CS/From.cs#3)] + +For more information about join operations that use multiple `from` clauses, see [Perform left outer joins](../../linq/perform-left-outer-joins.md). + +## See also + +[Query Keywords (LINQ)](query-keywords.md) +[Language Integrated Query (LINQ)](../../linq/index.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/keywords/int.md b/docs/csharp/language-reference/keywords/int.md index 4725936dc5b65..584a1bf2ec384 100644 --- a/docs/csharp/language-reference/keywords/int.md +++ b/docs/csharp/language-reference/keywords/int.md @@ -12,9 +12,9 @@ ms.assetid: 212447b4-5d2a-41aa-88ab-84fe710bdb52 `int` denotes an integral type that stores values according to the size and range shown in the following table. -|Type|Range|Size|.NET Framework type|Default Value| -|----------|-----------|----------|-------------------------|-------------------| -|`int`|-2,147,483,648 to 2,147,483,647|Signed 32-bit integer||0| +|Type|Range|Size|.NET type| +|----------|-----------|----------|-------------------------| +|`int`|-2,147,483,648 to 2,147,483,647|Signed 32-bit integer|| ## Literals diff --git a/docs/csharp/language-reference/keywords/long.md b/docs/csharp/language-reference/keywords/long.md index 4a0f46cb44d84..244ce99d96925 100644 --- a/docs/csharp/language-reference/keywords/long.md +++ b/docs/csharp/language-reference/keywords/long.md @@ -12,7 +12,7 @@ ms.assetid: f9b24319-1f39-48be-a42b-d528ee28a7fd `long` denotes an integral type that stores values according to the size and range shown in the following table. -|Type|Range|Size|.NET Framework type| +|Type|Range|Size|.NET type| |----------|-----------|----------|-------------------------| |`long`|-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807|Signed 64-bit integer|| diff --git a/docs/csharp/language-reference/keywords/sbyte.md b/docs/csharp/language-reference/keywords/sbyte.md index 9c8fface6e65d..581d057cbbb32 100644 --- a/docs/csharp/language-reference/keywords/sbyte.md +++ b/docs/csharp/language-reference/keywords/sbyte.md @@ -12,7 +12,7 @@ ms.assetid: 1a9c7b48-73d1-4d33-b485-c4faf0a816bc `sbyte` denotes an integral type that stores values according to the size and range shown in the following table. -|Type|Range|Size|.NET Framework type| +|Type|Range|Size|.NET type| |----------|-----------|----------|-------------------------| |`sbyte`|-128 to 127|Signed 8-bit integer|| diff --git a/docs/csharp/language-reference/keywords/short.md b/docs/csharp/language-reference/keywords/short.md index 6bd46ee32a481..828ae841fcd82 100644 --- a/docs/csharp/language-reference/keywords/short.md +++ b/docs/csharp/language-reference/keywords/short.md @@ -12,7 +12,7 @@ ms.assetid: 04c10688-e51a-4a87-bfec-83f7fb42ff11 `short` denotes an integral data type that stores values according to the size and range shown in the following table. -|Type|Range|Size|.NET Framework type| +|Type|Range|Size|.NET type| |----------|-----------|----------|-------------------------| |`short`|-32,768 to 32,767|Signed 16-bit integer|| diff --git a/docs/csharp/language-reference/keywords/uint.md b/docs/csharp/language-reference/keywords/uint.md index a18f9b770ea6e..a4cada02b3588 100644 --- a/docs/csharp/language-reference/keywords/uint.md +++ b/docs/csharp/language-reference/keywords/uint.md @@ -12,7 +12,7 @@ ms.assetid: e93e42c6-ec72-4b0b-89df-2fd8d36f7a7b The `uint` keyword signifies an integral type that stores values according to the size and range shown in the following table. -|Type|Range|Size|.NET Framework type| +|Type|Range|Size|.NET type| |----------|-----------|----------|-------------------------| |`uint`|0 to 4,294,967,295|Unsigned 32-bit integer|| diff --git a/docs/csharp/language-reference/keywords/ulong.md b/docs/csharp/language-reference/keywords/ulong.md index 6fd5cd033b58b..c9bf76f66e6e4 100644 --- a/docs/csharp/language-reference/keywords/ulong.md +++ b/docs/csharp/language-reference/keywords/ulong.md @@ -12,7 +12,7 @@ ms.assetid: f2ece624-837a-40cf-92c5-343e7f33397c The `ulong` keyword denotes an integral type that stores values according to the size and range shown in the following table. -|Type|Range|Size|.NET Framework type| +|Type|Range|Size|.NET type| |----------|-----------|----------|-------------------------| |`ulong`|0 to 18,446,744,073,709,551,615|Unsigned 64-bit integer|| diff --git a/docs/csharp/language-reference/keywords/ushort.md b/docs/csharp/language-reference/keywords/ushort.md index e8c5283737b61..47ede5e7f72da 100644 --- a/docs/csharp/language-reference/keywords/ushort.md +++ b/docs/csharp/language-reference/keywords/ushort.md @@ -12,7 +12,7 @@ ms.assetid: 1a7dbaae-b7a0-4111-872a-c88a6d3981ac The `ushort` keyword indicates an integral data type that stores values according to the size and range shown in the following table. -|Type|Range|Size|.NET Framework type| +|Type|Range|Size|.NET type| |----------|-----------|----------|-------------------------| |`ushort`|0 to 65,535|Unsigned 16-bit integer|| diff --git a/docs/framework/data/adonet/ef/language-reference/entity-sql-reference.md b/docs/framework/data/adonet/ef/language-reference/entity-sql-reference.md index a2770c5afee65..7c47b71316576 100644 --- a/docs/framework/data/adonet/ef/language-reference/entity-sql-reference.md +++ b/docs/framework/data/adonet/ef/language-reference/entity-sql-reference.md @@ -1,128 +1,139 @@ --- -title: "Entity SQL Reference" +title: "Entity SQL reference" ms.date: "03/30/2017" ms.assetid: 61ce7ee1-ffe2-477d-8a9f-835b0a11d900 --- -# Entity SQL Reference -This section contains [!INCLUDE[esql](../../../../../../includes/esql-md.md)] reference topics. This topic summarizes and groups the [!INCLUDE[esql](../../../../../../includes/esql-md.md)] operators by category. - -## Arithmetic Operators - Arithmetic operators perform mathematical operations on two expressions of one or more numeric data types. The following table lists the [!INCLUDE[esql](../../../../../../includes/esql-md.md)] arithmetic operators. - -|Operator|Use| -|--------------|---------| -|[+ (Add)](../../../../../../docs/framework/data/adonet/ef/language-reference/add.md)|Addition.| -|"/ (Divide)"|Division.| -|[% (Modulo)](../../../../../../docs/framework/data/adonet/ef/language-reference/modulo-entity-sql.md)|Returns the remainder of a division.| -|[* (Multiply)](../../../../../../docs/framework/data/adonet/ef/language-reference/multiply-entity-sql.md)|Multiplication.| -|[- (Negative)](../../../../../../docs/framework/data/adonet/ef/language-reference/negative-entity-sql.md)|Negation.| -|[- (Subtract)](../../../../../../docs/framework/data/adonet/ef/language-reference/subtract-entity-sql.md)|Subtraction.| - -## Canonical Functions - Canonical functions are supported by all data providers and can be used by all querying technologies. The following table lists the canonical functions. - -|Function|Type| -|--------------|----------| -|[Aggregate Entity SQL Canonical Functions](../../../../../../docs/framework/data/adonet/ef/language-reference/aggregate-canonical-functions.md)|Discusses aggregate [!INCLUDE[esql](../../../../../../includes/esql-md.md)] canonical functions.| -|[Math Canonical Functions](../../../../../../docs/framework/data/adonet/ef/language-reference/math-canonical-functions.md)|Discusses math [!INCLUDE[esql](../../../../../../includes/esql-md.md)] canonical functions.| -|[String Canonical Functions](../../../../../../docs/framework/data/adonet/ef/language-reference/string-canonical-functions.md)|Discusses string [!INCLUDE[esql](../../../../../../includes/esql-md.md)] canonical functions.| -|[Date and Time Canonical Functions](../../../../../../docs/framework/data/adonet/ef/language-reference/date-and-time-canonical-functions.md)|Discusses date and time [!INCLUDE[esql](../../../../../../includes/esql-md.md)] canonical functions.| -|[Bitwise Canonical Functions](../../../../../../docs/framework/data/adonet/ef/language-reference/bitwise-canonical-functions.md)|Discusses bitwise [!INCLUDE[esql](../../../../../../includes/esql-md.md)] canonical functions.| -|[Other Canonical Functions](../../../../../../docs/framework/data/adonet/ef/language-reference/other-canonical-functions.md)|Discusses functions not classified as bitwise, date/time, string, math, or aggregate.| - -## Comparison Operators - Comparison operators are defined for the following types: `Byte`, `Int16`, `Int32`, `Int64`, `Double`, `Single`, `Decimal`, `String`, `DateTime`, `Date`, `Time`, `DateTimeOffset`. Implicit type promotion occurs for the operands before the comparison operator is applied. Comparison operators always yield Boolean values. When at least one of the operands is `null`, the result is `null`. - - Equality and inequality are defined for any object type that has identity, such as the `Boolean` type. Non-primitive objects with identity are considered equal if they share the same identity. The following table lists the [!INCLUDE[esql](../../../../../../includes/esql-md.md)] comparison operators. - -|Operator|Description| -|--------------|-----------------| -|[= (Equals)](../../../../../../docs/framework/data/adonet/ef/language-reference/equals-entity-sql.md)|Compares the equality of two expressions.| -|[> (Greater Than)](../../../../../../docs/framework/data/adonet/ef/language-reference/greater-than-entity-sql.md)|Compares two expressions to determine whether the left expression has a value greater than the right expression.| -|[>= (Greater Than or Equal To)](../../../../../../docs/framework/data/adonet/ef/language-reference/greater-than-or-equal-to-entity-sql.md)|Compares two expressions to determine whether the left expression has a value greater than or equal to the right expression.| -|[IS [NOT] NULL](../../../../../../docs/framework/data/adonet/ef/language-reference/isnull-entity-sql.md)|Determines if a query expression is null.| -|[< (Less Than)](../../../../../../docs/framework/data/adonet/ef/language-reference/less-than-entity-sql.md)|Compares two expressions to determine whether the left expression has a value less than the right expression.| -|[<= (Less Than or Equal To)](../../../../../../docs/framework/data/adonet/ef/language-reference/less-than-or-equal-to-entity-sql.md)|Compares two expressions to determine whether the left expression has a value less than or equal to the right expression.| -|[[NOT] BETWEEN](../../../../../../docs/framework/data/adonet/ef/language-reference/between-entity-sql.md)|Determines whether an expression results in a value in a specified range.| -|[!= (Not Equal To)](../../../../../../docs/framework/data/adonet/ef/language-reference/not-equal-to-entity-sql.md)|Compares two expressions to determine whether the left expression is not equal to the right expression.| -|[[NOT] LIKE](../../../../../../docs/framework/data/adonet/ef/language-reference/like-entity-sql.md)|Determines whether a specific character string matches a specified pattern.| - -## Logical and Case Expression Operators - Logical operators test for the truth of a condition. The CASE expression evaluates a set of Boolean expressions to determine the result. The following table lists the logical and CASE expression operators. - -|Operator|Description| -|--------------|-----------------| -|[&& (Logical AND)](../../../../../../docs/framework/data/adonet/ef/language-reference/and-entity-sql.md)|Logical AND.| -|[! (Logical NOT)](../../../../../../docs/framework/data/adonet/ef/language-reference/not-entity-sql.md)|Logical NOT.| -|[|| (Logical OR)](../../../../../../docs/framework/data/adonet/ef/language-reference/or-entity-sql.md)|Logical OR.| -|[CASE](../../../../../../docs/framework/data/adonet/ef/language-reference/case-entity-sql.md)|Evaluates a set of Boolean expressions to determine the result.| -|[THEN](../../../../../../docs/framework/data/adonet/ef/language-reference/then-entity-sql.md)|The result of a [WHEN](http://msdn.microsoft.com/library/6233fe9f-00b0-460e-8372-64e138a5f998) clause when it evaluates to true.| - -## Query Operators - Query operators are used to define query expressions that return entity data. The following table lists query operators. - -|Operator|Use| -|--------------|---------| -|[FROM](../../../../../../docs/framework/data/adonet/ef/language-reference/from-entity-sql.md)|Specifies the collection that is used in [SELECT](../../../../../../docs/framework/data/adonet/ef/language-reference/select-entity-sql.md) statements.| -|[GROUP BY](../../../../../../docs/framework/data/adonet/ef/language-reference/group-by-entity-sql.md)|Specifies groups into which objects that are returned by a query ([SELECT](../../../../../../docs/framework/data/adonet/ef/language-reference/select-entity-sql.md)) expression are to be placed.| -|[GroupPartition](../../../../../../docs/framework/data/adonet/ef/language-reference/grouppartition-entity-sql.md)|Returns a collection of argument values, projected off the group partition to which the aggregate is related.| -|[HAVING](../../../../../../docs/framework/data/adonet/ef/language-reference/having-entity-sql.md)|Specifies a search condition for a group or an aggregate.| -|[LIMIT](../../../../../../docs/framework/data/adonet/ef/language-reference/limit-entity-sql.md)|Used with the [ORDER BY](../../../../../../docs/framework/data/adonet/ef/language-reference/order-by-entity-sql.md) clause to performed physical paging.| -|[ORDER BY](../../../../../../docs/framework/data/adonet/ef/language-reference/order-by-entity-sql.md)|Specifies the sort order that is used on objects returned in a [SELECT](../../../../../../docs/framework/data/adonet/ef/language-reference/select-entity-sql.md) statement.| -|[SELECT](../../../../../../docs/framework/data/adonet/ef/language-reference/select-entity-sql.md)|Specifies the elements in the projection that are returned by a query.| -|[SKIP](../../../../../../docs/framework/data/adonet/ef/language-reference/skip-entity-sql.md)|Used with the [ORDER BY](../../../../../../docs/framework/data/adonet/ef/language-reference/order-by-entity-sql.md) clause to performed physical paging.| -|[TOP](../../../../../../docs/framework/data/adonet/ef/language-reference/top-entity-sql.md)|Specifies that only the first set of rows will be returned from the query result.| -|[WHERE](../../../../../../docs/framework/data/adonet/ef/language-reference/where-entity-sql.md)|Conditionally filters data that is returned by a query.| - -## Reference Operators - A reference is a logical pointer (foreign key) to a specific entity in a specific entity set. [!INCLUDE[esql](../../../../../../includes/esql-md.md)] supports the following operators to construct, deconstruct, and navigate through references. - -|Operator|Use| -|--------------|---------| -|[CREATEREF](../../../../../../docs/framework/data/adonet/ef/language-reference/createref-entity-sql.md)|Creates references to an entity in an entity set.| -|[DEREF](../../../../../../docs/framework/data/adonet/ef/language-reference/deref-entity-sql.md)|Dereferences a reference value and produces the result of that dereference.| -|[KEY](../../../../../../docs/framework/data/adonet/ef/language-reference/key-entity-sql.md)|Extracts the key of a reference or of an entity expression.| -|[NAVIGATE](../../../../../../docs/framework/data/adonet/ef/language-reference/navigate-entity-sql.md)|Allows you to navigate over the relationship from one entity type to another| -|[REF](../../../../../../docs/framework/data/adonet/ef/language-reference/ref-entity-sql.md)|Returns a reference to an entity instance.| - -## Set Operators - [!INCLUDE[esql](../../../../../../includes/esql-md.md)] provides various powerful set operations. This includes set operators similar to Transact-SQL operators such as UNION, INTERSECT, EXCEPT, and EXISTS. [!INCLUDE[esql](../../../../../../includes/esql-md.md)] also supports operators for duplicate elimination (SET), membership testing (IN), and joins (JOIN). The following table lists the [!INCLUDE[esql](../../../../../../includes/esql-md.md)] set operators. - -|Operator|Use| -|--------------|---------| -|[ANYELEMENT](../../../../../../docs/framework/data/adonet/ef/language-reference/anyelement-entity-sql.md)|Extracts an element from a multivalued collection.| -|[EXCEPT](../../../../../../docs/framework/data/adonet/ef/language-reference/except-entity-sql.md)|Returns a collection of any distinct values from the query expression to the left of the EXCEPT operand that are not also returned from the query expression to the right of the EXCEPT operand.| -|[[NOT] EXISTS](../../../../../../docs/framework/data/adonet/ef/language-reference/exists-entity-sql.md)|Determines if a collection is empty.| -|[FLATTEN](../../../../../../docs/framework/data/adonet/ef/language-reference/flatten-entity-sql.md)|Converts a collection of collections into a flattened collection.| -|[[NOT] IN](../../../../../../docs/framework/data/adonet/ef/language-reference/in-entity-sql.md)|Determines whether a value matches any value in a collection.| -|[INTERSECT](../../../../../../docs/framework/data/adonet/ef/language-reference/intersect-entity-sql.md)|Returns a collection of any distinct values that are returned by both the query expressions on the left and right sides of the INTERSECT operand.| -|[OVERLAPS](../../../../../../docs/framework/data/adonet/ef/language-reference/overlaps-entity-sql.md)|Determines whether two collections have common elements.| -|[SET](../../../../../../docs/framework/data/adonet/ef/language-reference/set-entity-sql.md)|Used to convert a collection of objects into a set by yielding a new collection with all duplicate elements removed.| -|[UNION](../../../../../../docs/framework/data/adonet/ef/language-reference/union-entity-sql.md)|Combines the results of two or more queries into a single collection.| - -## Type Operators - [!INCLUDE[esql](../../../../../../includes/esql-md.md)] provides operations that allow the type of an expression (value) to be constructed, queried, and manipulated. The following table lists operators that are used to work with types. - -|Operator|Use| -|--------------|---------| -|[CAST](../../../../../../docs/framework/data/adonet/ef/language-reference/cast-entity-sql.md)|Converts an expression of one data type to another.| -|[COLLECTION](../../../../../../docs/framework/data/adonet/ef/language-reference/collection-entity-sql.md)|Used in a [FUNCTION](../../../../../../docs/framework/data/adonet/ef/language-reference/function-entity-sql.md) operation to declare a collection of entity types or complex types.| -|[IS [NOT] OF](../../../../../../docs/framework/data/adonet/ef/language-reference/isof-entity-sql.md)|Determines whether the type of an expression is of the specified type or one of its subtypes.| -|[OFTYPE](../../../../../../docs/framework/data/adonet/ef/language-reference/oftype-entity-sql.md)|Returns a collection of objects from a query expression that is of a specific type.| -|[Named Type Constructor](../../../../../../docs/framework/data/adonet/ef/language-reference/named-type-constructor-entity-sql.md)|Used to create instances of entity types or complex types.| -|[MULTISET](../../../../../../docs/framework/data/adonet/ef/language-reference/multiset-entity-sql.md)|Creates an instance of a multiset from a list of values.| -|[ROW](../../../../../../docs/framework/data/adonet/ef/language-reference/row-entity-sql.md)|Constructs anonymous, structurally typed records from one or more values.| -|[TREAT](../../../../../../docs/framework/data/adonet/ef/language-reference/treat-entity-sql.md)|Treats an object of a particular base type as an object of the specified derived type.| - -## Other Operators - The following table lists other [!INCLUDE[esql](../../../../../../includes/esql-md.md)] operators. - -|Operator|Use| -|--------------|---------| -|[+ (String Concatenation)](../../../../../../docs/framework/data/adonet/ef/language-reference/string-concatenation-entity-sql.md)|Used to concatenate strings in [!INCLUDE[esql](../../../../../../includes/esql-md.md)].| -|[. (Member Access)](../../../../../../docs/framework/data/adonet/ef/language-reference/member-access-entity-sql.md)|Used to access the value of a property or field of an instance of structural conceptual model type.| -|[-- (Comment)](../../../../../../docs/framework/data/adonet/ef/language-reference/comment-entity-sql.md)|Include [!INCLUDE[esql](../../../../../../includes/esql-md.md)] comments.| -|[FUNCTION](../../../../../../docs/framework/data/adonet/ef/language-reference/function-entity-sql.md)|Defines an inline function that can be executed in an Entity SQL query.| - -## See Also - [Entity SQL Language](../../../../../../docs/framework/data/adonet/ef/language-reference/entity-sql-language.md) +# Entity SQL reference + +This section contains Entity SQL reference articles. This article summarizes and groups the Entity SQL operators by category. + +## Arithmetic operators + +Arithmetic operators perform mathematical operations on two expressions of one or more numeric data types. The following table lists the Entity SQL arithmetic operators: + +|Operator|Use| +|--------------|---------| +|[+ (Add)](add.md)|Addition.| +|[/ (Divide)](divide-entity-sql.md)|Division.| +|[% (Modulo)](modulo-entity-sql.md)|Returns the remainder of a division.| +|[* (Multiply)](multiply-entity-sql.md)|Multiplication.| +|[- (Negative)](negative-entity-sql.md)|Negation.| +|[- (Subtract)](subtract-entity-sql.md)|Subtraction.| + +## Canonical functions + +Canonical functions are supported by all data providers and can be used by all querying technologies. The following table lists the canonical functions: + +|Function|Type| +|--------------|----------| +|[Aggregate Entity SQL Canonical Functions](aggregate-canonical-functions.md)|Discusses aggregate Entity SQL canonical functions.| +|[Math Canonical Functions](math-canonical-functions.md)|Discusses math Entity SQL canonical functions.| +|[String Canonical Functions](string-canonical-functions.md)|Discusses string Entity SQL canonical functions.| +|[Date and Time Canonical Functions](date-and-time-canonical-functions.md)|Discusses date and time Entity SQL canonical functions.| +|[Bitwise Canonical Functions](bitwise-canonical-functions.md)|Discusses bitwise Entity SQL canonical functions.| +|[Other Canonical Functions](other-canonical-functions.md)|Discusses functions not classified as bitwise, date/time, string, math, or aggregate.| + +## Comparison operators + +Comparison operators are defined for the following types: `Byte`, `Int16`, `Int32`, `Int64`, `Double`, `Single`, `Decimal`, `String`, `DateTime`, `Date`, `Time`, `DateTimeOffset`. Implicit type promotion occurs for the operands before the comparison operator is applied. Comparison operators always yield Boolean values. When at least one of the operands is `null`, the result is `null`. + +Equality and inequality are defined for any object type that has identity, such as the `Boolean` type. Non-primitive objects with identity are considered equal if they share the same identity. The following table lists the Entity SQL comparison operators: + +|Operator|Description| +|--------------|-----------------| +|[= (Equals)](equals-entity-sql.md)|Compares the equality of two expressions.| +|[> (Greater Than)](greater-than-entity-sql.md)|Compares two expressions to determine whether the left expression has a value greater than the right expression.| +|[>= (Greater Than or Equal To)](greater-than-or-equal-to-entity-sql.md)|Compares two expressions to determine whether the left expression has a value greater than or equal to the right expression.| +|[IS [NOT] NULL](isnull-entity-sql.md)|Determines if a query expression is null.| +|[< (Less Than)](less-than-entity-sql.md)|Compares two expressions to determine whether the left expression has a value less than the right expression.| +|[<= (Less Than or Equal To)](less-than-or-equal-to-entity-sql.md)|Compares two expressions to determine whether the left expression has a value less than or equal to the right expression.| +|[[NOT] BETWEEN](between-entity-sql.md)|Determines whether an expression results in a value in a specified range.| +|[!= (Not Equal To)](not-equal-to-entity-sql.md)|Compares two expressions to determine whether the left expression isn't equal to the right expression.| +|[[NOT] LIKE](like-entity-sql.md)|Determines whether a specific character string matches a specified pattern.| + +## Logical and case expression operators + +Logical operators test for the truth of a condition. The CASE expression evaluates a set of Boolean expressions to determine the result. The following table lists the logical and CASE expression operators: + +|Operator|Description| +|--------------|-----------------| +|[&& (Logical AND)](and-entity-sql.md)|Logical AND.| +|[! (Logical NOT)](not-entity-sql.md)|Logical NOT.| +|[|| (Logical OR)](or-entity-sql.md)|Logical OR.| +|[CASE](case-entity-sql.md)|Evaluates a set of Boolean expressions to determine the result.| +|[THEN](then-entity-sql.md)|The result of a [WHEN](http://msdn.microsoft.com/library/6233fe9f-00b0-460e-8372-64e138a5f998) clause when it evaluates to true.| + +## Query operators + +Query operators are used to define query expressions that return entity data. The following table lists query operators: + +|Operator|Use| +|--------------|---------| +|[FROM](from-entity-sql.md)|Specifies the collection that is used in [SELECT](select-entity-sql.md) statements.| +|[GROUP BY](group-by-entity-sql.md)|Specifies groups into which objects that are returned by a query ([SELECT](select-entity-sql.md)) expression are to be placed.| +|[GroupPartition](grouppartition-entity-sql.md)|Returns a collection of argument values, projected off the group partition to which the aggregate is related.| +|[HAVING](having-entity-sql.md)|Specifies a search condition for a group or an aggregate.| +|[LIMIT](limit-entity-sql.md)|Used with the [ORDER BY](order-by-entity-sql.md) clause to performed physical paging.| +|[ORDER BY](order-by-entity-sql.md)|Specifies the sort order that is used on objects returned in a [SELECT](select-entity-sql.md) statement.| +|[SELECT](select-entity-sql.md)|Specifies the elements in the projection that are returned by a query.| +|[SKIP](skip-entity-sql.md)|Used with the [ORDER BY](order-by-entity-sql.md) clause to performed physical paging.| +|[TOP](top-entity-sql.md)|Specifies that only the first set of rows will be returned from the query result.| +|[WHERE](where-entity-sql.md)|Conditionally filters data that is returned by a query.| + +## Reference operators + +A reference is a logical pointer (foreign key) to a specific entity in a specific entity set. Entity SQL supports the following operators to construct, deconstruct, and navigate through references: + +|Operator|Use| +|--------------|---------| +|[CREATEREF](createref-entity-sql.md)|Creates references to an entity in an entity set.| +|[DEREF](deref-entity-sql.md)|Dereferences a reference value and produces the result of that dereference.| +|[KEY](key-entity-sql.md)|Extracts the key of a reference or of an entity expression.| +|[NAVIGATE](navigate-entity-sql.md)|Allows you to navigate over the relationship from one entity type to another| +|[REF](ref-entity-sql.md)|Returns a reference to an entity instance.| + +## Set operators + +Entity SQL provides various powerful set operations. This includes set operators similar to Transact-SQL operators such as UNION, INTERSECT, EXCEPT, and EXISTS. Entity SQL also supports operators for duplicate elimination (SET), membership testing (IN), and joins (JOIN). The following table lists the Entity SQL set operators: + +|Operator|Use| +|--------------|---------| +|[ANYELEMENT](anyelement-entity-sql.md)|Extracts an element from a multivalued collection.| +|[EXCEPT](except-entity-sql.md)|Returns a collection of any distinct values from the query expression to the left of the EXCEPT operand that aren't also returned from the query expression to the right of the EXCEPT operand.| +|[[NOT] EXISTS](exists-entity-sql.md)|Determines if a collection is empty.| +|[FLATTEN](flatten-entity-sql.md)|Converts a collection of collections into a flattened collection.| +|[[NOT] IN](in-entity-sql.md)|Determines whether a value matches any value in a collection.| +|[INTERSECT](intersect-entity-sql.md)|Returns a collection of any distinct values that are returned by both the query expressions on the left and right sides of the INTERSECT operand.| +|[OVERLAPS](overlaps-entity-sql.md)|Determines whether two collections have common elements.| +|[SET](set-entity-sql.md)|Used to convert a collection of objects into a set by yielding a new collection with all duplicate elements removed.| +|[UNION](union-entity-sql.md)|Combines the results of two or more queries into a single collection.| + +## Type operators + +Entity SQL provides operations that allow the type of an expression (value) to be constructed, queried, and manipulated. The following table lists operators that are used to work with types: + +|Operator|Use| +|--------------|---------| +|[CAST](cast-entity-sql.md)|Converts an expression of one data type to another.| +|[COLLECTION](collection-entity-sql.md)|Used in a [FUNCTION](function-entity-sql.md) operation to declare a collection of entity types or complex types.| +|[IS [NOT] OF](isof-entity-sql.md)|Determines whether the type of an expression is of the specified type or one of its subtypes.| +|[OFTYPE](oftype-entity-sql.md)|Returns a collection of objects from a query expression that is of a specific type.| +|[Named Type Constructor](named-type-constructor-entity-sql.md)|Used to create instances of entity types or complex types.| +|[MULTISET](multiset-entity-sql.md)|Creates an instance of a multiset from a list of values.| +|[ROW](row-entity-sql.md)|Constructs anonymous, structurally typed records from one or more values.| +|[TREAT](treat-entity-sql.md)|Treats an object of a particular base type as an object of the specified derived type.| + +## Other operators + +The following table lists other Entity SQL operators: + +|Operator|Use| +|--------------|---------| +|[+ (String Concatenation)](string-concatenation-entity-sql.md)|Used to concatenate strings in Entity SQL.| +|[. (Member Access)](member-access-entity-sql.md)|Used to access the value of a property or field of an instance of structural conceptual model type.| +|[-- (Comment)](comment-entity-sql.md)|Include Entity SQL comments.| +|[FUNCTION](function-entity-sql.md)|Defines an inline function that can be executed in an Entity SQL query.| + +## See also + +[Entity SQL Language](entity-sql-language.md) diff --git a/docs/framework/data/adonet/sql/linq/boolean-data-types.md b/docs/framework/data/adonet/sql/linq/boolean-data-types.md index da82ce3665e30..01eed6b135c13 100644 --- a/docs/framework/data/adonet/sql/linq/boolean-data-types.md +++ b/docs/framework/data/adonet/sql/linq/boolean-data-types.md @@ -15,7 +15,7 @@ Boolean operators work as expected in the common language runtime (CLR), except |[Or Operator](~/docs/visual-basic/language-reference/operators/or-operator.md)|[| Operator](~/docs/csharp/language-reference/operators/or-operator.md)| |[OrElse Operator](~/docs/visual-basic/language-reference/operators/orelse-operator.md)|[|| Operator](~/docs/csharp/language-reference/operators/conditional-or-operator.md)| |[Xor Operator](~/docs/visual-basic/language-reference/operators/xor-operator.md)|[^ Operator](~/docs/csharp/language-reference/operators/xor-operator.md)| -|[Not Operator](~/docs/visual-basic/language-reference/operators/not-operator.md)|[! Operator](~/docs/csharp/language-reference/operators/logical-negation-operator.md)| +|[Not Operator](~/docs/visual-basic/language-reference/operators/not-operator.md)|[\! Operator](~/docs/csharp/language-reference/operators/logical-negation-operator.md)| ## See Also [Data Types and Functions](../../../../../../docs/framework/data/adonet/sql/linq/data-types-and-functions.md) diff --git a/docs/framework/interop/default-marshaling-behavior.md b/docs/framework/interop/default-marshaling-behavior.md index 61c2ed17334c6..4fd4d4e3832f2 100644 --- a/docs/framework/interop/default-marshaling-behavior.md +++ b/docs/framework/interop/default-marshaling-behavior.md @@ -1,6 +1,6 @@ --- title: "Default Marshaling Behavior" -ms.date: "03/30/2017" +ms.date: "06/26/2018" dev_langs: - "csharp" - "vb" @@ -107,7 +107,9 @@ interface DelegateTest : IDispatch { ``` A function pointer can be dereferenced, just as any other unmanaged function pointer can be dereferenced. - + +In this example, when the two delegates are marshaled as , the result is an `int` and a pointer to an `int`. Because delegate types are being marshaled, `int` here represents a pointer to a void (`void*`), which is the address of the delegate in memory. In other words, this result is specific to 32-bit Windows systems, since `int` here represents the size of the function pointer. + > [!NOTE] > A reference to the function pointer to a managed delegate held by unmanaged code does not prevent the common language runtime from performing garbage collection on the managed object. diff --git a/docs/framework/network-programming/how-to-download-files-with-ftp.md b/docs/framework/network-programming/how-to-download-files-with-ftp.md index c0b2971aaee29..c689a9b00efa2 100644 --- a/docs/framework/network-programming/how-to-download-files-with-ftp.md +++ b/docs/framework/network-programming/how-to-download-files-with-ftp.md @@ -1,55 +1,76 @@ --- -title: "How to: Download Files with FTP" -ms.date: "03/30/2017" +title: "How to: Download files with FTP" +description: "This article shows a sample of how to download a file from an FTP server." +ms.date: "06/26/2018" +dev_langs: + - "csharp" + - "vb" ms.assetid: 892548b8-954a-4f6a-9bca-2ae620c3700f -author: "mcleblanc" -ms.author: "markl" -manager: "markl" --- -# How to: Download Files with FTP -This sample shows how to download a file from an FTP server. - -## Example - -```csharp -using System; -using System.IO; -using System.Net; -using System.Text; - -namespace Examples.System.Net -{ - public class WebRequestGetExample - { - public static void Main () - { - // Get the object used to communicate with the server. - FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm"); - request.Method = WebRequestMethods.Ftp.DownloadFile; - - // This example assumes the FTP site uses anonymous logon. - request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com"); - - FtpWebResponse response = (FtpWebResponse)request.GetResponse(); - - Stream responseStream = response.GetResponseStream(); - StreamReader reader = new StreamReader(responseStream); - Console.WriteLine(reader.ReadToEnd()); - - Console.WriteLine("Download Complete, status {0}", response.StatusDescription); - - reader.Close(); - response.Close(); - } - } -} -``` - -## Compiling the Code - This example requires: - -- References to the **System.Net** namespace. - -## Robust Programming - -## .NET Framework Security +# How to: Download files with FTP + +This sample shows how to download a file from an FTP server. + +## Example + +```csharp +using System; +using System.IO; +using System.Net; + +namespace Examples.System.Net +{ + public class WebRequestGetExample + { + public static void Main () + { + // Get the object used to communicate with the server. + FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm"); + request.Method = WebRequestMethods.Ftp.DownloadFile; + + // This example assumes the FTP site uses anonymous logon. + request.Credentials = new NetworkCredential("anonymous","janeDoe@contoso.com"); + + FtpWebResponse response = (FtpWebResponse)request.GetResponse(); + + Stream responseStream = response.GetResponseStream(); + StreamReader reader = new StreamReader(responseStream); + Console.WriteLine(reader.ReadToEnd()); + + Console.WriteLine($"Download Complete, status {response.StatusDescription}"); + + reader.Close(); + response.Close(); + } + } +} +``` + +```vb +Imports System.IO +Imports System.Net + +Namespace Examples.System.Net + Public Module WebRequestGetExample + Public Sub Main() + ' Get the object used to communicate with the server. + Dim request As FtpWebRequest = CType(WebRequest.Create("ftp://www.contoso.com/test.htm"), FtpWebRequest) + request.Method = WebRequestMethods.Ftp.DownloadFile + + ' This example assumes the FTP site uses anonymous logon. + request.Credentials = New NetworkCredential("anonymous", "janeDoe@contoso.com") + + Dim response As FtpWebResponse = CType(request.GetResponse(), FtpWebResponse) + + Dim responseStream As Stream = response.GetResponseStream() + Dim reader As StreamReader = New StreamReader(responseStream) + Console.WriteLine(reader.ReadToEnd()) + + Console.WriteLine($"Download Complete, status {response.StatusDescription}") + + reader.Close() + response.Close() + End Sub + End Module +End Namespace +``` \ No newline at end of file diff --git a/docs/framework/network-programming/how-to-list-directory-contents-with-ftp.md b/docs/framework/network-programming/how-to-list-directory-contents-with-ftp.md index f328b61fd40f9..37ed38a15f6b5 100644 --- a/docs/framework/network-programming/how-to-list-directory-contents-with-ftp.md +++ b/docs/framework/network-programming/how-to-list-directory-contents-with-ftp.md @@ -1,55 +1,76 @@ --- -title: "How to: List Directory Contents with FTP" -ms.date: "03/30/2017" +title: "How to: List directory contents with FTP" +description: "This article shows a sample of how to list the directory contents of an FTP server." +ms.date: "06/26/2018" +dev_langs: + - "csharp" + - "vb" ms.assetid: 130c64c9-7b7f-4672-9b3b-d946bd2616c5 -author: "mcleblanc" -ms.author: "markl" -manager: "markl" --- -# How to: List Directory Contents with FTP -This sample shows how to list the directory contents of an FTP server. - -## Example - -```csharp -using System; -using System.IO; -using System.Net; -using System.Text; - -namespace Examples.System.Net -{ - public class WebRequestGetExample - { - public static void Main () - { - // Get the object used to communicate with the server. - FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/"); - request.Method = WebRequestMethods.Ftp.ListDirectoryDetails; - - // This example assumes the FTP site uses anonymous logon. - request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com"); - - FtpWebResponse response = (FtpWebResponse)request.GetResponse(); - - Stream responseStream = response.GetResponseStream(); - StreamReader reader = new StreamReader(responseStream); - Console.WriteLine(reader.ReadToEnd()); - - Console.WriteLine("Directory List Complete, status {0}", response.StatusDescription); - - reader.Close(); - response.Close(); - } - } -} -``` - -## Compiling the Code - This example requires: - -- References to the **System.Net** namespace. - -## Robust Programming - -## .NET Framework Security +# How to: List directory contents with FTP + +This sample shows how to list the directory contents of an FTP server. + +## Example + +```csharp +using System; +using System.IO; +using System.Net; + +namespace Examples.System.Net +{ + public class WebRequestGetExample + { + public static void Main () + { + // Get the object used to communicate with the server. + FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/"); + request.Method = WebRequestMethods.Ftp.ListDirectoryDetails; + + // This example assumes the FTP site uses anonymous logon. + request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com"); + + FtpWebResponse response = (FtpWebResponse)request.GetResponse(); + + Stream responseStream = response.GetResponseStream(); + StreamReader reader = new StreamReader(responseStream); + Console.WriteLine(reader.ReadToEnd()); + + Console.WriteLine($"Directory List Complete, status {response.StatusDescription}"); + + reader.Close(); + response.Close(); + } + } +} +``` + +```vb +Imports System.IO +Imports System.Net + +Namespace Examples.System.Net + Public Module WebRequestGetExample + Public Sub Main() + ' Get the object used to communicate with the server. + Dim request As FtpWebRequest = CType(WebRequest.Create("ftp://www.contoso.com/"), FtpWebRequest) + request.Method = WebRequestMethods.Ftp.ListDirectoryDetails + + ' This example assumes the FTP site uses anonymous logon. + request.Credentials = New NetworkCredential("anonymous", "janeDoe@contoso.com") + + Dim response As FtpWebResponse = CType(request.GetResponse(), FtpWebResponse) + + Dim responseStream As Stream = response.GetResponseStream() + Dim reader As StreamReader = New StreamReader(responseStream) + Console.WriteLine(reader.ReadToEnd()) + + Console.WriteLine($"Directory List Complete, status {response.StatusDescription}") + + reader.Close() + response.Close() + End Sub + End Module +End Namespace +``` \ No newline at end of file diff --git a/docs/framework/network-programming/how-to-upload-files-with-ftp.md b/docs/framework/network-programming/how-to-upload-files-with-ftp.md index c5b7f5740add2..5f35d9ef8d610 100644 --- a/docs/framework/network-programming/how-to-upload-files-with-ftp.md +++ b/docs/framework/network-programming/how-to-upload-files-with-ftp.md @@ -1,42 +1,44 @@ --- -title: "How to: Upload Files with FTP" -ms.date: "03/30/2017" +title: "How to: Upload files with FTP" +description: "This article shows a sample of how to upload a file to an FTP server." +ms.date: "06/26/2018" +dev_langs: + - "csharp" + - "vb" ms.assetid: e40f17c5-dd12-4c62-9dbf-00ab491382dc -author: "mcleblanc" -ms.author: "markl" -manager: "markl" --- -# How to: Upload Files with FTP -This sample shows how to upload a file to an FTP server. - -## Example - -```csharp -using System; -using System.IO; -using System.Net; -using System.Text; - -namespace Examples.System.Net -{ - public class WebRequestGetExample - { - public static void Main () - { - // Get the object used to communicate with the server. +# How to: Upload files with FTP + +This sample shows how to upload a file to an FTP server. + +## Example + +```csharp +using System; +using System.IO; +using System.Net; +using System.Text; + +namespace Examples.System.Net +{ + public class WebRequestGetExample + { + public static void Main () + { + // Get the object used to communicate with the server. FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm"); request.Method = WebRequestMethods.Ftp.UploadFile; - // This example assumes the FTP site uses anonymous logon. + // This example assumes the FTP site uses anonymous logon. request.Credentials = new NetworkCredential("anonymous", "janeDoe@contoso.com"); - // Copy the contents of the file to the request stream. + // Copy the contents of the file to the request stream. byte[] fileContents; using (StreamReader sourceStream = new StreamReader("testfile.txt")) { fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd()); } - + request.ContentLength = fileContents.Length; using (Stream requestStream = request.GetRequestStream()) @@ -46,18 +48,45 @@ namespace Examples.System.Net using (FtpWebResponse response = (FtpWebResponse)request.GetResponse()) { - Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription); + Console.WriteLine($"Upload File Complete, status {response.StatusDescription}"); } - } - } -} -``` - -## Compiling the Code - This example requires: - -- References to the **System.Net** namespace. - -## Robust Programming - -## .NET Framework Security + } + } +} +``` + +```vb +Imports System.IO +Imports System.Net +Imports System.Text + +Namespace Examples.System.Net + Public Module WebRequestGetExample + Public Sub Main() + ' Get the object used to communicate with the server. + Dim request As FtpWebRequest = CType(WebRequest.Create("ftp://www.contoso.com/test.htm"), FtpWebRequest) + request.Method = WebRequestMethods.Ftp.UploadFile + + ' This example assumes the FTP site uses anonymous logon. + request.Credentials = New NetworkCredential("anonymous", "janeDoe@contoso.com") + + ' Copy the contents of the file to the request stream. + Dim fileContents As Byte() + + Using sourceStream As StreamReader = New StreamReader("testfile.txt") + fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd()) + End Using + + request.ContentLength = fileContents.Length + + Using requestStream As Stream = request.GetRequestStream() + requestStream.Write(fileContents, 0, fileContents.Length) + End Using + + Using response As FtpWebResponse = CType(request.GetResponse(), FtpWebResponse) + Console.WriteLine($"Upload File Complete, status {response.StatusDescription}") + End Using + End Sub + End Module +End Namespace +``` \ No newline at end of file diff --git a/docs/framework/wcf/feature-details/generating-a-wcf-client-from-service-metadata.md b/docs/framework/wcf/feature-details/generating-a-wcf-client-from-service-metadata.md index 31f77915a5d58..b5e998914039b 100644 --- a/docs/framework/wcf/feature-details/generating-a-wcf-client-from-service-metadata.md +++ b/docs/framework/wcf/feature-details/generating-a-wcf-client-from-service-metadata.md @@ -14,7 +14,7 @@ This topic describes how to use the various switches in Svcutil.exe to generate - DISCO request (using the [DiscoveryClientProtocol](http://go.microsoft.com/fwlink/?LinkId=94777) from ASP.NET Web services) to the supplied address. - Svcutil.exe generates the client based on the Web Services Description Language (WSDL) or policy file received from the service. The user principal name (UPN) is generated by concatenating the user name with "@" and then adding a fully-qualified domain name (FQDN). However, for users who registered on Active Directory, this format is not valid and the UPN that the tool generates causes a failure in the Kerberos authentication with the following error message: **The logon attempt failed.** To resolve this problem, manually fix the client file that the tool generated. + Svcutil.exe generates the client based on the Web Services Description Language (WSDL) or policy file received from the service. The user principal name (UPN) is generated by concatenating the user name with "\@" and then adding a fully-qualified domain name (FQDN). However, for users who registered on Active Directory, this format is not valid and the UPN that the tool generates causes a failure in the Kerberos authentication with the following error message: **The logon attempt failed.** To resolve this problem, manually fix the client file that the tool generated. ``` svcutil.exe [/t:code] * | * | diff --git a/docs/framework/wcf/feature-details/how-to-access-services-with-a-duplex-contract.md b/docs/framework/wcf/feature-details/how-to-access-services-with-a-duplex-contract.md index bbba1fc6853ae..0a2a9ba3475cc 100644 --- a/docs/framework/wcf/feature-details/how-to-access-services-with-a-duplex-contract.md +++ b/docs/framework/wcf/feature-details/how-to-access-services-with-a-duplex-contract.md @@ -1,5 +1,5 @@ --- -title: "How to: Access Services with a Duplex Contract" +title: "How to: Access services with a duplex contract" ms.date: "03/30/2017" dev_langs: - "csharp" @@ -8,83 +8,83 @@ helpviewer_keywords: - "duplex contracts [WCF]" ms.assetid: 746a9d64-f21c-426c-b85d-972e916ec6c5 --- -# How to: Access Services with a Duplex Contract -One feature of Windows Communication Foundation (WCF) is the ability to create a service that uses a duplex messaging pattern. This pattern allows a service to communicate with the client through a callback. This topic shows the steps to create a WCF client in a client class that implements the callback interface. - - A dual binding exposes the IP address of the client to the service. The client should use security to ensure that it connects only to services it trusts. - - For a tutorial on creating a basic WCF service and client, see [Getting Started Tutorial](../../../../docs/framework/wcf/getting-started-tutorial.md). - -### To access a duplex service - -1. Create a service that contains two interfaces. The first interface is for the service, the second is for the callback. For more information about creating a duplex service, see [How to: Create a Duplex Contract](../../../../docs/framework/wcf/feature-details/how-to-create-a-duplex-contract.md). - -2. Run the service. - -3. Use the [ServiceModel Metadata Utility Tool (Svcutil.exe)](../../../../docs/framework/wcf/servicemodel-metadata-utility-tool-svcutil-exe.md) to generate contracts (interfaces) for the client. For information about how to do this, see [How to: Create a Client](../../../../docs/framework/wcf/how-to-create-a-wcf-client.md). - -4. Implement the callback interface in the client class, as shown in the following example. - - ```csharp - public class CallbackHandler : ICalculatorDuplexCallback - { - public void Result(double result) - { - Console.WriteLine("Result ({0})", result); - } - public void Equation(string equation) - { - Console.WriteLine("Equation({0})", equation); - } - } - ``` - - ```vb - Public Class CallbackHandler - Implements ICalculatorDuplexCallback - Public Sub Result (ByVal result As Double) - Console.WriteLine("Result ({0})", result) - End Sub - Public Sub Equation(ByVal equation As String) - Console.Writeline("Equation({0})", equation) - End Sub - End Class - ``` - -5. Create an instance of the class. The constructor requires an instance of the client class. - - ```csharp - InstanceContext site = new InstanceContext(new CallbackHandler()); - ``` - - ```vb - Dim site As InstanceContext = New InstanceContext(new CallbackHandler()) - ``` - -6. Create an instance of the WCF client using the constructor that requires an object. The second parameter of the constructor is the name of an endpoint found in the configuration file. - - ```csharp - CalculatorDuplexClient wcfClient = - new CalculatorDuplexClient(site, "default") - ``` - - ```vb - Dim wcfClient As New CalculatorDuplexClient(site, "default") - ``` - -7. Call the methods of the WCF client as required. - -## Example - The following code example demonstrates how to create a client class that accesses a duplex contract. - - [!code-csharp[S_DuplexClients#1](../../../../samples/snippets/csharp/VS_Snippets_CFX/s_duplexclients/cs/client.cs#1)] - [!code-vb[S_DuplexClients#1](../../../../samples/snippets/visualbasic/VS_Snippets_CFX/s_duplexclients/vb/client.vb#1)] - -## .NET Framework Security - -## See Also - [Getting Started Tutorial](../../../../docs/framework/wcf/getting-started-tutorial.md) - [How to: Create a Duplex Contract](../../../../docs/framework/wcf/feature-details/how-to-create-a-duplex-contract.md) - [ServiceModel Metadata Utility Tool (Svcutil.exe)](../../../../docs/framework/wcf/servicemodel-metadata-utility-tool-svcutil-exe.md) - [How to: Create a Client](../../../../docs/framework/wcf/how-to-create-a-wcf-client.md) - [How to: Use the ChannelFactory](../../../../docs/framework/wcf/feature-details/how-to-use-the-channelfactory.md) +# How to: Access services with a duplex contract + +One feature of Windows Communication Foundation (WCF) is the ability to create a service that uses a duplex messaging pattern. This pattern allows a service to communicate with the client through a callback. This topic shows the steps to create a WCF client in a client class that implements the callback interface. + +A dual binding exposes the IP address of the client to the service. The client should use security to ensure that it connects only to services it trusts. + +For a tutorial on creating a basic WCF service and client, see [Getting Started Tutorial](../../../../docs/framework/wcf/getting-started-tutorial.md). + +## To access a duplex service + +1. Create a service that contains two interfaces. The first interface is for the service, the second is for the callback. For more information about creating a duplex service, see [How to: Create a Duplex Contract](../../../../docs/framework/wcf/feature-details/how-to-create-a-duplex-contract.md). + +2. Run the service. + +3. Use the [ServiceModel Metadata Utility Tool (Svcutil.exe)](../../../../docs/framework/wcf/servicemodel-metadata-utility-tool-svcutil-exe.md) to generate contracts (interfaces) for the client. For information about how to do this, see [How to: Create a Client](../../../../docs/framework/wcf/how-to-create-a-wcf-client.md). + +4. Implement the callback interface in the client class, as shown in the following example. + + ```csharp + public class CallbackHandler : ICalculatorDuplexCallback + { + public void Result(double result) + { + Console.WriteLine("Result ({0})", result); + } + public void Equation(string equation) + { + Console.WriteLine("Equation({0})", equation); + } + } + ``` + + ```vb + Public Class CallbackHandler + Implements ICalculatorDuplexCallback + Public Sub Result (ByVal result As Double) + Console.WriteLine("Result ({0})", result) + End Sub + Public Sub Equation(ByVal equation As String) + Console.Writeline("Equation({0})", equation) + End Sub + End Class + ``` + +5. Create an instance of the class. The constructor requires an instance of the client class. + + ```csharp + InstanceContext site = new InstanceContext(new CallbackHandler()); + ``` + + ```vb + Dim site As InstanceContext = New InstanceContext(new CallbackHandler()) + ``` + +6. Create an instance of the WCF client using the constructor that requires an object. The second parameter of the constructor is the name of an endpoint found in the configuration file. + + ```csharp + CalculatorDuplexClient wcfClient = new CalculatorDuplexClient(site, "default"); + ``` + + ```vb + Dim wcfClient As New CalculatorDuplexClient(site, "default") + ``` + +7. Call the methods of the WCF client as required. + +## Example + +The following code example demonstrates how to create a client class that accesses a duplex contract. + +[!code-csharp[S_DuplexClients#1](../../../../samples/snippets/csharp/VS_Snippets_CFX/s_duplexclients/cs/client.cs#1)] +[!code-vb[S_DuplexClients#1](../../../../samples/snippets/visualbasic/VS_Snippets_CFX/s_duplexclients/vb/client.vb#1)] + +## See also + +[Getting Started Tutorial](../../../../docs/framework/wcf/getting-started-tutorial.md) +[How to: Create a Duplex Contract](../../../../docs/framework/wcf/feature-details/how-to-create-a-duplex-contract.md) +[ServiceModel Metadata Utility Tool (Svcutil.exe)](../../../../docs/framework/wcf/servicemodel-metadata-utility-tool-svcutil-exe.md) +[How to: Create a Client](../../../../docs/framework/wcf/how-to-create-a-wcf-client.md) +[How to: Use the ChannelFactory](../../../../docs/framework/wcf/feature-details/how-to-use-the-channelfactory.md) diff --git a/docs/framework/wpf/controls/how-to-group-sort-and-filter-data-in-the-datagrid-control.md b/docs/framework/wpf/controls/how-to-group-sort-and-filter-data-in-the-datagrid-control.md index 885ebf95f6c0c..c3e60809a8a23 100644 --- a/docs/framework/wpf/controls/how-to-group-sort-and-filter-data-in-the-datagrid-control.md +++ b/docs/framework/wpf/controls/how-to-group-sort-and-filter-data-in-the-datagrid-control.md @@ -1,153 +1,148 @@ --- -title: "How to: Group, Sort, and Filter Data in the DataGrid Control" +title: "How to: Group, sort, and filter Data in the DataGrid control" ms.date: "03/30/2017" -dev_langs: - - "csharp" - - "vb" -helpviewer_keywords: - - "DataGrid [WPF], sort" - - "DataGrid [WPF], group" - - "DataGrid [WPF], filter" +dev_langs: + - "csharp" + - "vb" +helpviewer_keywords: + - "DataGrid [WPF], sort" + - "DataGrid [WPF], group" + - "DataGrid [WPF], filter" ms.assetid: 03345e85-89e3-4aec-9ed0-3b80759df770 --- -# How to: Group, Sort, and Filter Data in the DataGrid Control -It is often useful to view data in a in different ways by grouping, sorting, and filtering the data. To group, sort, and filter the data in a , you bind it to a that supports these functions. You can then work with the data in the without affecting the underlying source data. The changes in the collection view are reflected in the user interface (UI). - - The class provides grouping and sorting functionality for a data source that implements the interface. The class enables you to set the properties of a from XAML. - - In this example, a collection of `Task` objects is bound to a . The is used as the for the . Grouping, sorting, and filtering are performed on the and are displayed in the UI. - - ![Grouped data in a DataGrid](../../../../docs/framework/wpf/controls/media/wpf-datagridgroups.png "WPF_DataGridGroups") -Grouped Data in a DataGrid - -## Using a CollectionViewSource as an ItemsSource - To group, sort, and filter data in a control, you bind the to a that supports these functions. In this example, the is bound to a that provides these functions for a of `Task` objects. - -#### To bind a DataGrid to a CollectionViewSource - -1. Create a data collection that implements the interface. - - If you use to create your collection, you should create a new class that inherits from instead of instantiating an instance of . This enables you to data bind to the collection in XAML. - +# How to: Group, sort, and filter data in the DataGrid control + +It is often useful to view data in a in different ways by grouping, sorting, and filtering the data. To group, sort, and filter the data in a , you bind it to a that supports these functions. You can then work with the data in the without affecting the underlying source data. The changes in the collection view are reflected in the user interface (UI). + +The class provides grouping and sorting functionality for a data source that implements the interface. The class enables you to set the properties of a from XAML. + +In this example, a collection of `Task` objects is bound to a . The is used as the for the . Grouping, sorting, and filtering are performed on the and are displayed in the UI. + +![Grouped data in a DataGrid](./media/wpf-datagridgroups.png "WPF_DataGridGroups") +Grouped data in a DataGrid + +## Using a CollectionViewSource as an ItemsSource + +To group, sort, and filter data in a control, you bind the to a that supports these functions. In this example, the is bound to a that provides these functions for a of `Task` objects. + +### To bind a DataGrid to a CollectionViewSource + +1. Create a data collection that implements the interface. + + If you use to create your collection, you should create a new class that inherits from instead of instantiating an instance of . This enables you to data bind to the collection in XAML. + > [!NOTE] - > The objects in the collection must implement the changed interface and the interface in order for the to respond correctly to property changes and edits. For more information, see [Implement Property Change Notification](../../../../docs/framework/wpf/data/how-to-implement-property-change-notification.md). - - [!code-csharp[DataGrid_GroupSortFilter#101](../../../../samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml.cs#101)] - [!code-vb[DataGrid_GroupSortFilter#101](../../../../samples/snippets/visualbasic/VS_Snippets_Wpf/DataGrid_GroupSortFilter/VB/MainWindow.xaml.vb#101)] - -2. In XAML, create an instance of the collection class and set the [x:Key Directive](../../../../docs/framework/xaml-services/x-key-directive.md). - -3. In XAML, create an instance of the class, set the [x:Key Directive](../../../../docs/framework/xaml-services/x-key-directive.md), and set the instance of your collection class as the . - - [!code-xaml[DataGrid_GroupSortFilter#201](../../../../samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/WindowSnips1.xaml#201)] - -4. Create an instance of the class, and set the property to the . - - [!code-xaml[DataGrid_GroupSortFilter#002](../../../../samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml#002)] - -5. To access the from your code, use the method to get a reference to the . - - [!code-csharp[DataGrid_GroupSortFilter#102](../../../../samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml.cs#102)] - [!code-vb[DataGrid_GroupSortFilter#102](../../../../samples/snippets/visualbasic/VS_Snippets_Wpf/DataGrid_GroupSortFilter/VB/MainWindow.xaml.vb#102)] - -## Grouping items in a DataGrid - To specify how items are grouped in a , you use the type to group the items in the source view. - -#### To group items in a DataGrid using XAML - -1. Create a that specifies the property to group by. You can specify the property in XAML or in code. - - 1. In XAML, set the to the name of the property to group by. - - 2. In code, pass the name of the property to group by to the constructor. - -2. Add the to the collection. - -3. Add additional instances of to the collection to add more levels of grouping. - - [!code-xaml[DataGrid_GroupSortFilter#012](../../../../samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml#012)] - - [!code-csharp[DataGrid_GroupSortFilter#112](../../../../samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml.cs#112)] - [!code-vb[DataGrid_GroupSortFilter#112](../../../../samples/snippets/visualbasic/VS_Snippets_Wpf/DataGrid_GroupSortFilter/VB/MainWindow.xaml.vb#112)] - -4. To remove a group, remove the from the collection. - -5. To remove all groups, call the method of the collection. - - [!code-csharp[DataGrid_GroupSortFilter#114](../../../../samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml.cs#114)] - [!code-vb[DataGrid_GroupSortFilter#114](../../../../samples/snippets/visualbasic/VS_Snippets_Wpf/DataGrid_GroupSortFilter/VB/MainWindow.xaml.vb#114)] - - When items are grouped in the , you can define a that specifies the appearance of each group. You apply the by adding it to the collection of the DataGrid. If you have multiple levels of grouping, you can apply different styles to each group level. Styles are applied in the order in which they are defined. For example, if you define two styles, the first will be applied to top level row groups. The second style will be applied to all row groups at the second level and lower. The of the is the that the group represents. - -#### To change the appearance of row group headers - -1. Create a that defines the appearance of the row group. - -2. Put the inside the `` tags. - - [!code-xaml[DataGrid_GroupSortFilter#003](../../../../samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml#003)] - -## Sorting items in a DataGrid - To specify how items are sorted in a , you use the type to sort the items in the source view. - -#### To sort items in a DataGrid - -1. Create a that specifies the property to sort by. You can specify the property in XAML or in code. - - 1. In XAML, set the to the name of the property to sort by. - - 2. In code, pass the name of the property to sort by and the to the constructor. - -2. Add the to the collection. - -3. Add additional instances of to the collection to sort by additional properties. - - [!code-xaml[DataGrid_GroupSortFilter#011](../../../../samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml#011)] - - [!code-csharp[DataGrid_GroupSortFilter#211](../../../../samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/WindowSnips1.xaml.cs#211)] - [!code-vb[DataGrid_GroupSortFilter#211](../../../../samples/snippets/visualbasic/VS_Snippets_Wpf/DataGrid_GroupSortFilter/VB/MainWindow.xaml.vb#211)] - -## Filtering items in a DataGrid - To filter items in a using a , you provide the filtering logic in the handler for the event. - -#### To filter items in a DataGrid - -1. Add a handler for the event. - -2. In the event handler, define the filtering logic. - - The filter will be applied every time the view is refreshed. - - [!code-xaml[DataGrid_GroupSortFilter#013](../../../../samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml#013)] - - [!code-csharp[DataGrid_GroupSortFilter#113](../../../../samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml.cs#113)] - [!code-vb[DataGrid_GroupSortFilter#113](../../../../samples/snippets/visualbasic/VS_Snippets_Wpf/DataGrid_GroupSortFilter/VB/MainWindow.xaml.vb#113)] - - Alternatively, you can filter items in a by creating a method that provides the filtering logic and setting the property to apply the filter. To see an example of this method, see [Filter Data in a View](../../../../docs/framework/wpf/data/how-to-filter-data-in-a-view.md). - -## Example - The following example demonstrates grouping, sorting, and filtering `Task` data in a and displaying the grouped, sorted, and filtered `Task` data in a . The is used as the for the . Grouping, sorting, and filtering are performed on the and are displayed in the UI. - - To test this example, you will need to adjust the DGGroupSortFilterExample name to match your project name. If you are using Visual Basic, you will need to change the class name for to the following. - - ` The objects in the collection must implement the changed interface and the interface in order for the to respond correctly to property changes and edits. For more information, see [Implement Property Change Notification](../data/how-to-implement-property-change-notification.md). + + [!code-csharp[DataGrid_GroupSortFilter#101](~/samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml.cs#101)] + [!code-vb[DataGrid_GroupSortFilter#101](~/samples/snippets/visualbasic/VS_Snippets_Wpf/DataGrid_GroupSortFilter/VB/MainWindow.xaml.vb#101)] + +2. In XAML, create an instance of the collection class and set the [x:Key Directive](../../../../docs/framework/xaml-services/x-key-directive.md). + +3. In XAML, create an instance of the class, set the [x:Key Directive](../../../../docs/framework/xaml-services/x-key-directive.md), and set the instance of your collection class as the . + + [!code-xaml[DataGrid_GroupSortFilter#201](~/samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/WindowSnips1.xaml#201)] + +4. Create an instance of the class, and set the property to the . + + [!code-xaml[DataGrid_GroupSortFilter#002](~/samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml#002)] + +5. To access the from your code, use the method to get a reference to the . + + [!code-csharp[DataGrid_GroupSortFilter#102](~/samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml.cs#102)] + [!code-vb[DataGrid_GroupSortFilter#102](~/samples/snippets/visualbasic/VS_Snippets_Wpf/DataGrid_GroupSortFilter/VB/MainWindow.xaml.vb#102)] + +## Grouping items in a DataGrid + +To specify how items are grouped in a , you use the type to group the items in the source view. + +### To group items in a DataGrid using XAML + +1. Create a that specifies the property to group by. You can specify the property in XAML or in code. + + 1. In XAML, set the to the name of the property to group by. + + 2. In code, pass the name of the property to group by to the constructor. + +2. Add the to the collection. + +3. Add additional instances of to the collection to add more levels of grouping. + + [!code-xaml[DataGrid_GroupSortFilter#012](~/samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml#012)] + [!code-csharp[DataGrid_GroupSortFilter#112](~/samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml.cs#112)] + [!code-vb[DataGrid_GroupSortFilter#112](~/samples/snippets/visualbasic/VS_Snippets_Wpf/DataGrid_GroupSortFilter/VB/MainWindow.xaml.vb#112)] + +4. To remove a group, remove the from the collection. + +5. To remove all groups, call the method of the collection. + + [!code-csharp[DataGrid_GroupSortFilter#114](~/samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml.cs#114)] + [!code-vb[DataGrid_GroupSortFilter#114](~/samples/snippets/visualbasic/VS_Snippets_Wpf/DataGrid_GroupSortFilter/VB/MainWindow.xaml.vb#114)] + +When items are grouped in the , you can define a that specifies the appearance of each group. You apply the by adding it to the collection of the DataGrid. If you have multiple levels of grouping, you can apply different styles to each group level. Styles are applied in the order in which they are defined. For example, if you define two styles, the first will be applied to top level row groups. The second style will be applied to all row groups at the second level and lower. The of the is the that the group represents. + +### To change the appearance of row group headers + +1. Create a that defines the appearance of the row group. + +2. Put the inside the `` tags. + + [!code-xaml[DataGrid_GroupSortFilter#003](~/samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml#003)] + +## Sorting items in a DataGrid + +To specify how items are sorted in a , you use the type to sort the items in the source view. + +### To sort items in a DataGrid + +1. Create a that specifies the property to sort by. You can specify the property in XAML or in code. + + 1. In XAML, set the to the name of the property to sort by. + + 2. In code, pass the name of the property to sort by and the to the constructor. + +2. Add the to the collection. + +3. Add additional instances of to the collection to sort by additional properties. + + [!code-xaml[DataGrid_GroupSortFilter#011](~/samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml#011)] + [!code-csharp[DataGrid_GroupSortFilter#211](~/samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/WindowSnips1.xaml.cs#211)] + [!code-vb[DataGrid_GroupSortFilter#211](~/samples/snippets/visualbasic/VS_Snippets_Wpf/DataGrid_GroupSortFilter/VB/MainWindow.xaml.vb#211)] + +## Filtering items in a DataGrid + +To filter items in a using a , you provide the filtering logic in the handler for the event. + +### To filter items in a DataGrid + +1. Add a handler for the event. + +2. In the event handler, define the filtering logic. + + The filter will be applied every time the view is refreshed. + + [!code-xaml[DataGrid_GroupSortFilter#013](~/samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml#013)] + [!code-csharp[DataGrid_GroupSortFilter#113](~/samples/snippets/csharp/VS_Snippets_Wpf/DataGrid_GroupSortFilter/CS/MainWindow.xaml.cs#113)] + [!code-vb[DataGrid_GroupSortFilter#113](~/samples/snippets/visualbasic/VS_Snippets_Wpf/DataGrid_GroupSortFilter/VB/MainWindow.xaml.vb#113)] + +Alternatively, you can filter items in a by creating a method that provides the filtering logic and setting the property to apply the filter. To see an example of this method, see [Filter Data in a View](../data/how-to-filter-data-in-a-view.md). + +## Example + +The following example demonstrates grouping, sorting, and filtering `Task` data in a and displaying the grouped, sorted, and filtered `Task` data in a . The is used as the for the . Grouping, sorting, and filtering are performed on the and are displayed in the UI. + +To test this example, you will need to adjust the DGGroupSortFilterExample name to match your project name. If you are using Visual Basic, you will need to change the class name for to the following. + +` and objects. +# How to: Encode and decode a JPEG image + +The following examples show how to decode and encode a JPEG image using the specific and objects. -## Example - This example demonstrates how to decode a [!INCLUDE[TLA2#tla_jpeg](../../../../includes/tla2sharptla-jpeg-md.md)] image using a from a . +## Example - Decode a JPEG image + +This example demonstrates how to decode a JPEG image using a from a . - [!code-cpp[JpegBitmapDecoderEncoder#1](../../../../samples/snippets/cpp/VS_Snippets_Wpf/JpegBitmapDecoderEncoder/CPP/jpegencoderdecoder.cpp#1)] - [!code-csharp[JpegBitmapDecoderEncoder#1](../../../../samples/snippets/csharp/VS_Snippets_Wpf/JpegBitmapDecoderEncoder/CSharp/JpegEncoderDecoder.cs#1)] - [!code-vb[JpegBitmapDecoderEncoder#1](../../../../samples/snippets/visualbasic/VS_Snippets_Wpf/JpegBitmapDecoderEncoder/VB/JpegEncoderDecoder.vb#1)] +[!code-cpp[JpegBitmapDecoderEncoder#1](~/samples/snippets/cpp/VS_Snippets_Wpf/JpegBitmapDecoderEncoder/CPP/jpegencoderdecoder.cpp#1)] +[!code-csharp[JpegBitmapDecoderEncoder#1](~/samples/snippets/csharp/VS_Snippets_Wpf/JpegBitmapDecoderEncoder/CSharp/JpegEncoderDecoder.cs#1)] +[!code-vb[JpegBitmapDecoderEncoder#1](~/samples/snippets/visualbasic/VS_Snippets_Wpf/JpegBitmapDecoderEncoder/VB/JpegEncoderDecoder.vb#1)] -## Example - This example demonstrates how to encode a into a [!INCLUDE[TLA2#tla_jpeg](../../../../includes/tla2sharptla-jpeg-md.md)] image using a . +## Example - Encode a JPEG image + +This example demonstrates how to encode a into a JPEG image using a . - [!code-cpp[JpegBitmapDecoderEncoder#4](../../../../samples/snippets/cpp/VS_Snippets_Wpf/JpegBitmapDecoderEncoder/CPP/jpegencoderdecoder.cpp#4)] - [!code-csharp[JpegBitmapDecoderEncoder#4](../../../../samples/snippets/csharp/VS_Snippets_Wpf/JpegBitmapDecoderEncoder/CSharp/JpegEncoderDecoder.cs#4)] - [!code-vb[JpegBitmapDecoderEncoder#4](../../../../samples/snippets/visualbasic/VS_Snippets_Wpf/JpegBitmapDecoderEncoder/VB/JpegEncoderDecoder.vb#4)] +[!code-cpp[JpegBitmapDecoderEncoder#4](~/samples/snippets/cpp/VS_Snippets_Wpf/JpegBitmapDecoderEncoder/CPP/jpegencoderdecoder.cpp#4)] +[!code-csharp[JpegBitmapDecoderEncoder#4](~/samples/snippets/csharp/VS_Snippets_Wpf/JpegBitmapDecoderEncoder/CSharp/JpegEncoderDecoder.cs#4)] +[!code-vb[JpegBitmapDecoderEncoder#4](~/samples/snippets/visualbasic/VS_Snippets_Wpf/JpegBitmapDecoderEncoder/VB/JpegEncoderDecoder.vb#4)] -## .NET Framework Security - -## See Also - [Imaging Overview](../../../../docs/framework/wpf/graphics-multimedia/imaging-overview.md) +## See also + +[Imaging Overview](../../../../docs/framework/wpf/graphics-multimedia/imaging-overview.md) \ No newline at end of file