Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
What is the purpose of "?" in (someDelegateName)?.Invoke();?

The following code snippet was highlighted in Visual Studio alongside a suggestion for simplifying it.

if ( drawMethodsDelegate != null )
    drawMethodsDelegate ( e.Graphics );

When I clicked on the lightbulb suggestion thing, Visual Studio refactored it into the following

drawMethodsDelegate?.Invoke ( e.Graphics );

And no. The question mark is not a typo. I don't understand what the question mark is used for and I can't find anything relevant on MSDN. I also looked at the Tutorial Point Delegates page but found no useful information.

Tutorial Point page , MSDN Delegates page , MSDN Control.Invoke page

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

This is the null conditional operator.

drawMethodsDelegate?.Invoke ( e.Graphics );

Provided that drawMethodsDelegate is not null calls the Invoke method. It is an operator that being introduced in the 6th version of C# and you can see it as a syntactic sugar, which helps you to write less code for handling null checks.

Last but not least, the above check is also thread-safe !

For further info please have a look here

over 4 years ago · Santiago Trujillo Denunciar

0

This is a null condition operator that came with C# 6.0

https://msdn.microsoft.com/en-us/library/dn986595.aspx

it means IF drawMethodsDelegate is not null Invoke the method else do nothing.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda