C
C#2mo ago
cypherpotato

✅ Difference between explicit and implicit operators

Hello there. What's the difference between defining an implicit and explicit operator? I would like to know the difference between
public static implicit operator JsonValue(JsonArray jarray) => jarray.AsJsonValue();
public static implicit operator JsonValue(JsonArray jarray) => jarray.AsJsonValue();
And
public static explicit operator JsonValue(JsonArray jarray) => jarray.AsJsonValue();
public static explicit operator JsonValue(JsonArray jarray) => jarray.AsJsonValue();
8 Replies
Angius
Angius2mo ago
It's in the docs
Jimmacle
Jimmacle2mo ago
basically, whether it happens implicitly or explicitly
Angius
Angius2mo ago
But tl;dr would be
var n = new MyNumber();
int a = n; // implicit
int b = (int)n; // explicit
var n = new MyNumber();
int a = n; // implicit
int b = (int)n; // explicit
cypherpotato
cypherpotato2mo ago
oh, I see. explicit operators requires the casting syntax
Angius
Angius2mo ago
Assuming MyNumber has cast operators to int
cypherpotato
cypherpotato2mo ago
thank you
viceroypenguin
viceroypenguin2mo ago
don't forget to $close
MODiX
MODiX2mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Want results from more Discord servers?
Add your server
More Posts
resource dictionary confusionSo this is a really weird question, so bear with me as I'm gonna try explaining. I am building a WPFWhat is the equivalent of this react component if made using C# and Blazor?I'm used to just doing .NET + React, but since they improved Blazor so much with .net 8 I'm having sApplication memory keeps increasingI have an application whose memory usage keeps increasing. The obvious thought is that I have a memoServe SPA (React) in ASP.NET web APIIs it a correct way to serve SPA in ASP.NET Web API project? Is there a better way to do it? The wayHow can i detect a new e-mail arrival using GraphClientServerI'm using Microsoft's outlook service through their graph library `Microsoft.Graph.` I make a login Concern over inheritance with static interface methodsConsider the following interface: ```cs public interface ILuaModel { static abstract void SetUseResolving External Components with Nested Components in NSwag for OpenAPI specsI am using NSwag to generate a C# client from an OpenAPI spec I want this spec to reference an exteLooking for help with database injection in NinjaTrader - Advanced(I think)I'm using NinjaTrader to build a fully automated trading bot. Right now the issue I'm having is thatHow to set Object from Inherited class with ReflectionsIm working on a framework for one of my libraries and my goal is to create a similar structure as DiIssue with unit test for Argon2-based password hash serviceI'm encountering an issue with the implementation of a password hash service using the Argon2 algori