Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Downgrade inline conditional from .net6 to .netframework 4.6.1

I have project written with .net6 core I’m trying to downgrade code to .NETframework 4.6.1 facing some issues with it, particularly conditional inline statement.

as I know in.NETframework conditional if usage like this

 var DecodedPayload = valid ? true : false

but in .net6 written like this with some additional part after statementز

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 var DecodedPayload = valid ? true : false, IsValid = valid

UPDATED

I think some important hints was missing in my question, maybe usefull to explain, this workinig code from .net6 I forgot to point that conditionl statment evaluated inside the return scope, see the original code .

   private VerifiedDecodedDataModel<TNotificationData> GetVerifiedDecodedData<TNotificationData>(string signedPayload)
        {
            if (string.IsNullOrEmpty(signedPayload))
            {
                throw new ArgumentNullException("Signed Payload is null");
            }

            var splitParts = signedPayload.Split('.'); // JWS header, payload, and signature representations

            EnsurePartElements(splitParts);

            var valid = VerifyToken(signedPayload);
            
            var payload = splitParts[1];

            return new VerifiedDecodedDataModel<TNotificationData> 
            {
                DecodedPayload = valid ? DecodeFromBase64<TNotificationData>(payload) : default,
                IsValid = valid
            };
        }

what the purpose of this addition after comma?

Thanks

>Solution :

Are you sure it didn’t say bool DecodedPayload = valid ? true : false, IsValid = valid; ? in which case: it defines two booleans, calculates the first via the conditional, then assignes the second from valid. Akin to two statements:

bool DecodedPayload = valid ? true : false;
bool IsValid = valid;

(note that the two lines are functionally identical, though!)

Note that var can only declare and assign one local, where-as explicit types can declare (and optionally assign) as many as you like of that same type – comma separated.

Note also: any such change is not related to the framework version, but rather: the language/compiler version, and: var goes back almost all the way (it was added in C# 3 at the same time as .NET Framework 3.5), so… I doubt you need to change anything here.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading