Overriding explicit and implicit conversion in C# .NET

Custom implicit and explicit conversions for numeric types can be defined in C# quite easily. You need to be aware of the “implicit”, “explicit” and “operator” keywords.

Consider the following class:

public class Measurement
{
	public int Value { get; set; }
}

Read more of this post

Advertisements

Overriding explicit and implicit conversion in C# .NET

Custom implicit and explicit conversions for numeric types can be defined in C# quite easily. You need to be aware of the “implicit”, “explicit” and “operator” keywords.

Consider the following class:

public class Measurement
{
	public int Value { get; set; }
}

Read more of this post

Type conversion example in C# .NET using the IConvertible interface

In this we saw how to convert between numeric types explicitly and implicitly. There are other ways to implement conversions in C#. You must have come across the System.Convert static methods such as System.ConvertToInt32 or System.ConvertToByte.

You can implement your own conversions by implementing the IConvertible interface. Consider the following object:

public class House
{
	public double Area { get; set; }
	public int NumberOfRooms { get; set; }
	public string Address { get; set; }
	public bool ForSale { get; set; }
        public DateTime DateBuilt { get; set; }
}

Read more of this post

Type conversion example in C# .NET using the IConvertible interface

In this we saw how to convert between numeric types explicitly and implicitly. There are other ways to implement conversions in C#. You must have come across the System.Convert static methods such as System.ConvertToInt32 or System.ConvertToByte.

You can implement your own conversions by implementing the IConvertible interface. Consider the following object:

public class House
{
	public double Area { get; set; }
	public int NumberOfRooms { get; set; }
	public string Address { get; set; }
	public bool ForSale { get; set; }
        public DateTime DateBuilt { get; set; }
}

Read more of this post

Overriding explicit and implicit conversion in C# .NET

Custom implicit and explicit conversions for numeric types can be defined in C# quite easily. You need to be aware of the “implicit”, “explicit” and “operator” keywords.

Consider the following class:

public class Measurement
{
	public int Value { get; set; }
}

Read more of this post

ultimatemindsettoday

A great WordPress.com site

Elliot Balynn's Blog

A directory of wonderful thoughts

Softwarearchitektur in der Praxis

Wissenswertes zu Webentwicklung, Domain-Driven Design und Microservices

Technology Talks

on Microsoft technologies, Web, Android and others

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

WEB APPLICATION DEVELOPMENT BEST PRACTICES WITH MICROSOFT STACK & ANGULAR

Cyber Matters

Bite-size insight on Cyber Security for the not too technical.

Guru N Guns's

OneSolution To dOTnET.

Johnny Zraiby

Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

%d bloggers like this: