pBook‎ > ‎

C# Knowledge QA


posted Apr 25, 2017, 4:40 AM by Javad Taghia


<Everyone who writes code>
<Describe the difference between a Thread and a Process?>
<A process has separate virtual address space. Two processes running on the same system at the same time do not overlap each other./>
<Every process has its own data segment as well as separate memory offset./>
<Processes use inter process communication techniques to interact with other processes./>
<Process has no synchronization overhead in the same way a thread has./>
<Threads are entities within a process. All threads of a process share its virtual address space and system resources but they have their own stack created./>
<All threads created by the process share the same data segment./>
<Threads do not need inter process communication techniques because they are not altogether separate address spaces. 
They share the same address space; therefore,they can directly communicate with other threads of the process./>
<Threads of a process share the same address space; therefore synchronizing the access to the shared data within the process's address space becomes very important./>
<Threads can be created quite easily and no duplication of resources is required./>

<What is a Windows Service and how does its lifecycle differ from a "standard" EXE?>
<Choose an exe if:>
<You need it to run on a per-user basis and only when a user is logged in/>
<You need it to interact with the Windows desktop (notification icons, etc.)/>
<It needs all the privileges of the logged-in user (no more, no less)/>
<Choose a service if:>
<It may need to run when no one is logged in/>
<It doesn't generally need per-user data or privilege/>
<It solely communicates with the network/>
<It needs to expose new "securable" objects. Objects that have their own Declarative Access Control Lists (DACL's) that limit access to certain accounts/groups./>
<It needs special permissions that may not be available to the logged-in user./>
<Services can easily be security holes, so prefer .exe's to services./>
<Sometimes you'll need both./> 
<A virus checker needs to be able to access every file on the filesystem/>
<which the current user may not be able to do),/>
<but it also needs to provide info to the user in the form of notification dialogs/pop-ups and a tool tray icon./>
<Services can't interact with the user's GUI directly./>
<They can use the standard Windows IPC (inter-process communication)/>
<services such as pipes and shared memory regions. Such tools usually have both a service and a per-user windowless .exe/>
<that communicates with the service using Windows pipes or shared memory regions./>
<Get "Programming Windows Security" by Keith Brown if you want to dive into these topics./>

<What is the maximum amount of memory any single process on Windows can address? Is this different than the maximum virtual memory for the system? How would this affect a system design?/>
<In a nutshell, 32 bit on 32 bit OS: 2 GB, unless set to large address space aware, in which case 3 GB. 32 bit on 64 bit OS: 2 GB, unless set to large address space aware, in which case 4 GB./>
<64 bit process: 2 GB, unless set to large address space aware, in which case it could address up to 8 TB, unless it is hosted on an Intel Itanium-based systems which is limited to 7 TB./>
<Microsoft states the various limits (by flavors and types) at: http://msdn.microsoft.com/en-us/library/aa366778.aspx/>

<What is the difference between an EXE and a DLL?>
<It's a executable file/>
<When loading an executable, no export is called, but only the module entry point./>
<When a system launches new executable, a new process is created/>
<The entry thread is called in context of main thread of that process./>
<It's a Dynamic Link Library/>
<There are multiple exported symbols./>
<The system loads a DLL into the context of an existing process./>

<What is strong-typing versus weak-typing? Which is preferred? Why?>
<Strong typing:>
< It checks the type of variables  as soon as possible, usually at compile time. It  prevents mixing operations between mismatched types.>
<A strong-typed programming language is one in which: />
<All variables (or data types) are known at compile time/>
<There is strict enforcement of typing rules (a String can't be used where an Integer would be expected)/>
<All exceptions to typing rules results in a compile time error/>
<Weak Typing:> 
<While weak typing is delaying checking the types of the system as late as possible, usually to run-time. In this you can mix types without an explicit conversion.>
<A "weak-typed" programming language is simply one which is not strong-typed./>
<which is preferred depeneds on what you want. for scripts and good stuff you will usually want weak typing, because you want to write as much less code as possible.
 in big programs, strong typing can reduce errors at compile time./>

<Corillian's product is a "Component Container." Name at least 3 component containers that ship now with the Windows Server Family.>
<a component is a class that implements the System.ComponentModel.IComponent interface or derives from a class that does./>
<A component is something that can be reused. C# is considered a component-oriented language. />
<Re-use is everything in component-oriented design/>
<A component can be added to the toolbox and dragged and dropped onto a form./>
<A control on the other hand is a component that provides a UI. />
<To do this you need to implement System.Windows.Forms.Control OR System.Web.UI.Control. />
<So a control is basically a component that has visual properties./>
<You need a place to hold your components and controls. This is done in a Container. />
<A Container is a class that implements the System.ComponentModel./>
<IContainer interface (directly or indirectly). Since this container holds your controls,/>
<it is easy to access the controls dynamically./>
<Three samples:>

<What is a PID? How is it useful when troubleshooting a system?>
<PID is process ID. />
<It’s an integer to identity a process running in the operating system./>
<It can be used to identify a process, start and kill a process in a multi-tasking system for troubleshooting. />
<Also in Visual Studio .NET, a process running in the operating system can be attached to the debugger to debug into the process./>

<How many processes can listen on a single TCP/IP port?>
<Only one/>

<What is the GAC? What problem does it solve?>
<A GAC stands for global assembly cache.>
<It’s a machine-wide code cache. An assembly deployed in GAC has a strong name, which contains a digital signature,/>
<publisher information, version number and culture information./>
<It solves “DLL Hell” problem./>

<What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?>
<The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array./>
<The CopyTo() method copies the elements into another existing array. Both perform a shallow copy./>
<A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array./>
<A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identacle object./>

<Explain ACID rule of thumb for transactions.>
<A transaction must be:>
<1. Atomic - it is one unit of work and does not dependent on previous and following transactions./>
<2. Consistent - data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t./>
<3. Isolated - no transaction sees the intermediate results of the current transaction)./>
<4. Durable - the values persist if the data had been committed even if the system crashes right after./>

<Mid-Level .NET Developer>
<Describe the difference between Interface-oriented, Object-oriented and Aspect-oriented programming.>
<- Interface oriented approach compels to develop the software based on the contract./>
<- Object oriented approach emphasizes on its aspects like:>
<- Abstraction/>
<- Encapsulation/>
<- Inheritance/>
<- Polymorphism/>
<- Cross cutting concerns cannot be implemented in object oriented programming.>
<- That’s not the case with aspect-oriented. However, there is a risk of system failure in this situation.>

<Describe what an Interface is and how it’s different from a Class.>
<An interface is a contract: it specifies what members (methods and properties) a class implementing the interface must have./>
<But because it is only a contract, it has no implementations for any of its members./>
<A class can implement zero, one or multiple interfaces./>

<What is Reflection?>
<Reflection is the ability of a managed code to read its own metadata for the purpose of finding assemblies, modules and type information at runtime./>
<In other words, reflection provides objects that encapsulate assemblies, modules and types./>
<A program reflects on itself by extracting metadata from its assembly and using that metadata either to inform the user or to modify its own behavior./>
<Reflection is similar to C++ RTTI (Runtime Type Information), but much broader in scope and capability./> 
<By using Reflection in C#, one is able to find out details of an object, method, and create objects and invoke methods at runtime./>
<The System.Reflection namespace contains classes and interfaces that provide a managed view of loaded types, methods, and fields, with the ability to dynamically create and invoke types./>
<When writing a C# code that uses reflection, the coder can use the typeof operator to get the object's type or use the GetType() method to get the type of the current instance./>

<What is the difference between XML Web Services using ASMX and .NET Remoting using SOAP?>
<- XML Web services are more restricted than objects exposed over .NET Remoting./>
<- XML Web services support open standards that target cross-platform use./>
<- XML Web services are generally easier to create and due to the restricted nature of XML Web services, the design issues are simplified./>
<- XML Web services support only SOAP message formatting, which uses larger XML text messages./>
<- Communication with .NET Remoting can be faster than XML Web service communication with a binary formatter./>
<- XML Web services are designed for use between companies and organizations./>
<- XML Web services don't require a dedicated hosting program because they are always hosted by ASP.NET./>
<- Consumers can use XML Web services just as easily as they can download HTML pages from the Internet./>
< Thus there's no need for an administrator to open additional ports on a firewall as they work through MS-IIS and ASP.NET/>

<Are the type system represented by XmlSchema and the CLS isomorphic?>
<Means every type defined by XML Schema can be defined in CLS (.NET type system) and vice versa./>

<Conceptually, what is the difference between early-binding and late-binding?>
<Early bound>
<The compiler can work out where the called function will be at compile time./>
<The compiler can guarantee early (before any of the programs code runs) that the function will exist and be callable at runtime./>
<The compiler guarantees that the function takes the right number of arguments and that they are of the correct type. It also checks that the return value is of the correct type./>
<like dynamoic/>
<The lookup will take longer because its not a simple offset calculation, there are usually text comparisons to be made./>
<The target function may not exist./>
<The target function may not accept the arguments passed to it, and may have a return value of the wrong type./>
<With some implementations, the target method can actually change at run-time. So, the lookup may execute a different function./>
<I think this happens in the Ruby language, you can define a new method on an object while the program is running./>
<Late-binding allows function calls to start calling a new override for a method instead of calling the existing base method./>

<Is using Assembly.Load a static reference or dynamic reference?>
<Assembly.Load is a dynamic reference since you're dynamically loading an external DLL at run-time./>
<You would consider a static reference more like when you're adding a reference to a .NET project and building the project with that reference in place./>
<Dynamic references facilitate inclusion of assemblies that are not necessarily part of my build./>

<When would using Assembly.LoadFrom or Assembly.LoadFile be appropriate?>
<I wanted to load a DLL at runtime, and the DLL lived in another directory. That DLL had its own dependencies (DLLs) which also lived in that same directory./>
<LoadFile(): Loaded the specific DLL, but not the dependencies. So when the first call was made from within the DLL to one of those other DLLs it threw a FileNotFoundException./>
<LoadFrom(): Loaded the DLL that I specified and also all the dependencies that lived in that directory./>

<What is an Asssembly Qualified Name? Is it a filename? How is it different?>
<An assembly qualified name is the internal name of the assembly, combained with the Assebly Version, Culture, and public Key: these cobination make it unique./>
<eg: mscorelib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089/>
<An assembly's name is stored in metadata and has a significant impact on the assembly's scope and use by an application./>
<The display name of an assembly is obtained using the Assembly.FullName property./>
<The runtime uses this information to locate the assembly and differentiate it from other assemblies with the same name./>
<You can use the Global Assembly Cache Tool (Gacutil.exe) to view the fully qualified name of an assembly in the global assembly cache./>
<You can view it through the command prompt, type : gacutil -l/>

<Is this valid? Assembly.Load("foo.dll");>
<No. Assembly.Load(string) takes the full name of the assembly (as contained in the GAC), not the name of the file./>

<How is a strongly-named assembly different from one that isn’t strongly-named?>
<Strongly-named assemblies can be loaded into the GAC and use key pairs to insure non-collision and authorship verification/>

<Can DateTimes be null?>
<No. They are structs, not objects./>

<What is the JIT? What is NGEN? What are limitations and benefits of each?>
<Just In Time Compiler compiles the code just before it is run./>
<- Due to this the code takes longer time to start however it is more efficient compilation since the compiler has more information about the target system./>
<- NGen is used to pre-just in time code which yields faster startup time but the compiler produces less efficient code because it has less information./>
<IT is Just-in-Time compiling, which natively compiles .NET code as it needs to be executed, allowing more flexibility in platform optimization./>
<NGEN is the Native Image Generator, a tool which precompiles native code for assemblies and caches it for execution, pre-empting JIT./>
<NGEN saves time at execution in exchange for potentially slowing execution on platforms other than the one it was originally executed for./>

<Differentiate between instance data and class data?>
<Class data in terms of static class is the data that particular class holds in its structure./>
<Instances can refer to different objects of the same class that hold different values using the same class structure in memory heap./>

<How does the generational garbage collector in the .NET CLR manage object lifetime? What is non-deterministic finalization?>
<The garbage collector defines objects into multiple generations based upon their expected lifecycle, and collects each generation with different frequency./>
<Non-deterministic finalization means that the Finalize() method of objects is not guaranteed to be called as soon as the object falls out of scope;/>
<It is executed when the garbage collector has time to prioritize it./>

<What is the difference between Finalize() and Dispose()?>
<Finalize() is called by the garbage collector before destroying an object, allowing it to clean up resources it may have allocated./>
<Dispose() is a method the programmer can call on an object to force resource deallocation (and pre-empt costly finalization)./>

<How is the using() pattern useful? What is IDisposable? How does it support deterministic finalization?>
<The using() construct allows you to mark a resource which is guaranteed to be disposed when the block exits./>
<IDisposable provides an interface for the Dispose() method, which allows a programmer to forcibly finalize an object/>
<while still placing a Finalize() method in it as a means of security in case another programmer neglects to use Dispose()/>

<What does this useful command line do? tasklist /m "mscor*">
<Allows you to see which processes currently running have loaded a specific library -- in this case, anything beginning with "MSCOR"./>

<What is the difference between in-proc and out-of-proc?>
<In-process communication is that between threads in a particular application space, as defined by the operating system./>
<Out-of-process communication is that between non-shared memory and process spaces./>

<What technology enables out-of-proc communication in .NET?>

<When you’re running a component within ASP.NET, what process is it running within on Windows XP? Windows 2000? Windows 2003?>
<XP & 2003: aspnet_wp.exe, 2000: inetinfo.exe/>

<Senior Developers/Architects>

<What’s wrong with a line like this? DateTime.Parse(myString);>
<Doesn't specify a locale or format./>

<What are PDBs? Where must they be located for debugging to work?>
<Program Database files. They contain references that connect the uncompiled code to the compiled code for debugging./>
<They must be located either in the same place as the EXE/DLL, or in your VS.NET specified symbols path./>

<What is cyclomatic complexity and why is it important?>
<It's a measure of the number of independent linearly executed paths through a program./>
<It's important for judging the complexity of software and assisting in determinations of which modules should be refactored into smaller components./>

<Write a standard lock() plus “double check” to create a critical section around a variable access.>
<--- bool notLocked = true;/>

<--- if (notLocked)/>
<--- {/>
<--- --- lock (typeof(lockingObject))/>
<--- --- {/>
<--- --- --- if (notLocked)/>
<--- --- --- {/>
<--- --- --- --- notLocked = false;/>
<--- --- --- --- foo = lockingObject;/>
<--- --- --- --- notLocked = true;/>
<--- --- --- }/>
<--- --- }/>
<--- }/>

<What is FullTrust? Do GAC’ed assemblies have FullTrust?>
<ullTrust means all .NET security permissions are granted to the assembly. GAC assemblies have FullTrust by default, but that can be changed by the user's security policy./>

<What benefit does your code receive if you decorate it with attributes demanding specific Security permissions?>
<Allows administrators to see exactly which permissions your application needs to run; prevents your code from being exploited beyond what permissions it absolutely needs;/>
<allows your application to forcibly fail instead of having to manually handle situations where it might be denied permissions it requires./>

<What does this do? gacutil /l | find /i "Corillian">
<Lists all assemblies in the GAC, searching for those whose names contain "Corillian"./>

<What does this do? sn -t foo.dll>
<Shows the token for foo.dll./>

<What ports must be open for DCOM over a firewall? What is the purpose of Port 135?>
<135 for the service control manager, 1024-65535 (or whatever range the administrator has restricted DCOM to) for applications./>

<Contrast OOP and SOA. What are tenets of each?>
<OOP tries to encapsulate functionality required to operate on data with the data structure itself, making objects "self-reliant"./>
<SOA aims to decouple functionality from data entirely, using interfaces to allow functional components to operate blindly with as little understanding of the precise/>
<nature of the data they're fed as possible, allowing many types of data sets to be fed into them for the same operation./>

<How does the XmlSerializer work? What ACL permissions does a process using it require?>
<Reflects the object and reads its interfaces to serialize them. Requires the .NET ReflectionPermission, obviously./>

<Why is catch(Exception) almost always a bad idea?>
<Because it swallows an exception without doing anything with it./>
<The only time this should really be used is when trying risky casts that you expect to have a reasonable likelihood of failure, but always of a very specific type./>

<What is the difference between Debug.Write and Trace.Write? When should each be used?>
<Debug.Write isn't compiled in if the project isn't built with the DEBUG symbol. Trace.Write calls are compiled regardless./>

<What is the difference between a Debug and Release build? Is there a significant speed difference? Why or why not?>
<elease builds don't contain debug symbols and are more compact and optimized./>

<Does JITting occur per-assembly or per-method? How does this affect the working set?>
<Per-method. This affects the working set because methods that aren't lined up for calls aren't loaded, reducing its footprint./>

<Contrast the use of an abstract base class against an interface?>
<Abstract classes can provide implementations for methods and properties. Interfaces only provide required declarations./>

<What is the difference between a.Equals(b) and a == b?>
<The first uses the object's equivalency constructor to see if it considers itself value-equal to the the second object./>
<The second construct compares their memory references to determine if they are the SAME object./>

<In the context of a comparison, what is object identity versus object equivalence?>
<Identity means that two references point to the same memory address. Equivalence means that two objects share the same value./>

<How would one do a deep copy in .NET?>
<Implement the IClonable interface, and define your implementation to execute deep copies on your subobjects (possibly through IClonable interfaces)./>
<Alternatively, serialize the object and then deserialize it into another object, but this is very slow compared to a dedicated cloning interface./>

<Explain current thinking around IClonable.>
<Clonable is preferable to using copy constructors because it is standardized and utilized by other portions of the .NET framework to generate object copies./>

<What is boxing?>
<Boxing and Unboxing are used to convert value types into reference types and vice versa./>
<Developers often need to make some methods generic and hence create methods that accept objects rather than specific value types./>
< The advantage of reference types is that they don’t create a copy of the object in memory, instead pass the reference of the data in the memory./>
<This uses memory much more efficiently, especially, if the object to be passed is very heavy./>
<int intVar2 = (int)objectVar;The object type is unboxed to the value type/>
<object objectVar = intVar1; boxing occurs. The integer type is parsed to object type/>

<Is string a value type or a reference type?>
<It's an "illusionary value type" that masks an interface to the System.String reference type./>

<What is the significance of the "PropertySpecified" pattern used by the XmlSerializer? What problem does it attempt to solve?>
<Defines the specific parameters that .NET class members serialize into. Solves the issue of an XML spec needing to have slightly different names for class members than the class itself does./>

<Why are out parameters a bad idea in .NET? Are they?>
<Out parameters create uncertainty about the data which may be returned from the function,/>
<and permit the caller to potentially pass bad references which your function must validate before using./>
<From a design standpoint, it's more elegant to define a custom class with multiple properties in the event that you need to return multiple values from a single function./>

<Can attributes be placed on specific parameters to a method? Why is this useful?>
<Yes. This might be needed to specify remoting implementations or types for method parameters, or to provide metadata for method parameters when exporting a code library./>


<C# Component Developers>

<Juxtapose the use of override with new. What is shadowing?>
<Override redefines an inherited method which was marked as virtual or abstract, and its access level must be the same as the method it overrides./>
<New allows you to completely hide an inherited member and create a different implementation of it with whatever attributes you choose./>
<Shadowing is another name for disabling an inherited method and redefining it./>

<Explain the use of virtual, sealed, override, and abstract.>
<irtual marks a method as overridable. Sealed marks a class as uninheritable./>
<Override redefines a method declared as virtual./>
<Abstract defines a class which cannot be instantiated, or a method which must be overriden in any derived classes./>

<Explain the importance and use of each component of this string: Foo.Bar, Version=, Culture=neutral, PublicKeyToken=593777ae2d274679d>
<Assembly name -- used for loading. Assembly version -- also used for loading. Culture -- defines culture settings used for string translation and other locale-specific settings./>
<PublicKeyToken -- used to uniquely identify this assembly and prevent collisions./>

<Explain the differences between public, protected, private and internal.>
<Public: accessible from any class. Private: accessible only from within the same class./>
<Protected: like private, but derived classes may also access./>
<Internal: like public, but accessible only by code within the same assembly./>

<What benefit do you get from using a Primary Interop Assembly (PIA)?>
<A PIA is a strongly-named assembly which defines COM interfaces for a component./>
<Because it is strongly-named, it can be loaded into the GAC and verified against the COM component's own signature to give the component collision-protection/>
<and authorship-verification benefits when interacing with .NET code./>

<By what mechanism does NUnit know what methods to test?>
<Reading attributes defined for classes and methods via reflection./>

<What is the difference between: catch(Exception e){throw e;} and catch(Exception e){throw;}>
<Both statements will catch and throw exception, but the latter will preserve the original exception stack./>

<What is the difference between typeof(foo) and myFoo.GetType()?>
<The first returns the object's type at compile time; the second returns it at runtime./>

<Explain what’s happening in the first constructor: public class c{ public c(string a) : this() {;}; public c() {;} } How is this construct useful?>
<The first constructor invokes the base constructor in addition to its own functionality;/>
<this would be useful if your base initialized basic field values or had other code that all other constructors would utilize./>

<What is this? Can this be used within a static method?>
<The "this" reference refers to the current object context. Static methods have no context, so it is not valid/>

<ASP.NET (UI) Developers>

<Describe how a browser-based Form POST becomes a Server-Side event like Button1_OnClick...>
<An ASP.NET Button control in HTML is an HTML input element with a type attribute set to "submit"./>
<A submit button in HTML invokes a POST, using the action attribute from the form element, which, for ASP.NET, is the current page./>
<Since this is a POST, the form variables are populated with all of the values from the input elements in the form element, including the value (name) of the submit button./>
<When the POST arrives at the server and is parsed by ASP.NET, it will acknowledge that the POST was initiated by the submit button, which is turned into a Click event for the original ASP.NET Button control./>


1-1 of 1