Skip to content

Latest commit

 

History

History
35 lines (31 loc) · 2.04 KB

File metadata and controls

35 lines (31 loc) · 2.04 KB
title implicit (C# Reference)
ms.date 07/20/2015
ms.prod .net
ms.technology
devlang-csharp
ms.topic article
f1_keywords
implicit
implicit_CSharpKeyword
helpviewer_keywords
implicit keyword [C#]
ms.assetid 34db590e-eb3a-4f11-88d0-ffb3cd753dab
caps.latest.revision 19
author BillWagner
ms.author wiwagn

implicit (C# Reference)

The implicit keyword is used to declare an implicit user-defined type conversion operator. Use it to enable implicit conversions between a user-defined type and another type, if the conversion is guaranteed not to cause a loss of data.

Example

[!code-csharpcsrefKeywordsConversion#5]

By eliminating unnecessary casts, implicit conversions can improve source code readability. However, because implicit conversions do not require programmers to explicitly cast from one type to the other, care must be taken to prevent unexpected results. In general, implicit conversion operators should never throw exceptions and never lose information so that they can be used safely without the programmer's awareness. If a conversion operator cannot meet those criteria, it should be marked explicit. For more information, see Using Conversion Operators.

C# Language Specification

[!INCLUDECSharplangspec]

See Also

C# Reference
C# Programming Guide
C# Keywords
explicit
operator (C# Reference)
How to: Implement User-Defined Conversions Between Structs