Interview Questions Answers.ORG
Interviewer And Interviewee Guide
Interviews
Quizzes
Home
Quizzes
Interviews Coding/Programming Interviews:Active Template Library (ATL)ActiveXApplication DeveloperArtificial intelligenceAssemblyAssociate Software EngineerAWKAWTC ProgrammingC++ ProgrammingCGI PerlCGI ProgrammingCMMICobolCritical ReasoningData Structures TreesDCOM COMDelphiDTDE4XExtensible Stylesheet Language (XSL)FortranFull-Stack DeveloperHaskellHTML DOMILUIPhone DeveloperJasper Reports DeveloperJava DeveloperLisp ProgrammingLotus NotesMicrosoft Foundation Class (MFC)Mobile DeveloperMVC DeveloperNode.jsOOPPascalPerl ProgrammingPHPPHP DeveloperProgrammingProgramming AlgorithmsProgramming ConceptsPythonRubyRuby on RailsRuby on Rails DeveloperSenior Front End DeveloperSenior Software DeveloperSignature ProgramSOASocket ProgrammingSoftware Development EngineerSoftware engineeringSr. PHP ProgrammerStack And QueueSTLSwift DeveloperTCL (Tool Command Language)Team Leader Android DeveloperUMLUnity 2D Games DeveloperUnity 3D DeveloperUnity DeveloperVBA (Visual Basic for Applications)Visual Basic (VB)Visual C++Web DevelopmentWin32APIWindows ProgramingWordPress DevelopmentWSDLXFormsXHTMLXLinkXMLXPathXQueryXSL-FOXSLT
Copyright © 2018. All Rights Reserved
Unity Developer Interview Question:
Tell me the role of structs in C#. Why would you choose to define a type as a struct instead of a class?
Submitted by: MuhammadStructs are used to create structures, a value type that is used to represent a record. Structs play a similar role to classes, which are a reference type in C#. Since structs are value types, they are allocated and deallocated on the stack or inline in containing types. This generally makes structs cheaper to allocate or deallocate than classes, which are reference types. Reference types are allocated on the heap and garbage-collected, which tends to take up more resources. If the instances of a type are small and short-lived, it makes sense to define a value type using structs.
The opposite is true when it comes to boxing and unboxing. A value type can get boxed when it is cast to a reference type or some other interface it implements. Because boxes are objects allocated to the heap and deallocated via garbage collection, too much boxing and unboxing of a value can negatively impact performance. Reference types like classes are preferred in these situations.
Submitted by: Muhammad
The opposite is true when it comes to boxing and unboxing. A value type can get boxed when it is cast to a reference type or some other interface it implements. Because boxes are objects allocated to the heap and deallocated via garbage collection, too much boxing and unboxing of a value can negatively impact performance. Reference types like classes are preferred in these situations.
Submitted by: Muhammad
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.
https://InterviewQuestionsAnswers.ORG.