Skip to content

SuneelPodapati/csharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

csharp

Super crazy C# doubts resolved in code

OptionalParameters

Tests the priority of Optional Parametric overload vs exact match overload. It also test the sizeof for custom structs with and without fields. An absolute match has higher priority than overloaded match with optional parameters.

MultiLevelInheritance

Inheritance through virtual, override, new and new virtual methods. Every new method with same name as in parent will create a new child method with same name and both will exists. To call the base version, we have to use the base reference.

StaticDirective and ref

Static directives holding to two methods with same name in different classes. In such scenerios we have to Call them with fully qualified name. Call by reference for reference types using ref allows to change the whole object itself and replace it with new object

ConstructorObjectInitializer

Determines the order of object initializer and parametric constructor, always constructors calls first follwed by object initializers

AsyncMain

Shows how to call async methods in a console app using Task.Run delegate and awaiting the result using GetAwaiter() call

BoxingUnBoxing

Shows that while boxing both the Value and the Type are stored with in the wrapped object. And hence we cannot unbox the object back to any other type that is compatible with the original boxed type. You can only unbox using the cast to the original type and assign to any compatible type but the unboxing cast should be only to the boxed type.

ThreadingWithLock

Shows how to access a common resource by multiple threads through lock statement in multithreaded program.

AutoResetEvent

Shows how the AutoResetEvent in a multi threaded program is used to signal the events to wait till the AutoResetEvent is Set or Reset.

CheckedUnchecked

Shows how an exception is raised in a checked context in run time if the overflow bit is set. The inner most enclosed context will get the priority to throw or surpress the run time overflow exceptions.

EnumFlags

Shows that a enum can inherit the integral value type and also how to use the enum for the bit flag operations using the Flag attribute on the enum declaration.

FrameworkEvents

Shows how to implement event using the Framework Guidlines.

DelegatesAsEventsAndHandlers

Shows that the event is just an access modifier on the delegate to declare that particular delegate as an event handler. Defines a custom delegate to implement an event behaviour as the framework's EventHandler delegate. Contains a Delegates class that contains the common delegates that the framework provides as its properties that can hold an methods with their corresponding signatures.

ForEachEffectedNoIEnumerable

This shows how a collection is affected by using the foreach iterator and modifying the collection with in the loop. Generally they are cached for performance and hence the iteration will continue on the initial collection. It also shows that the collection need not to implement the IEnumerable and the IEnumerator interfaces to be eligible for the foreach loop.

AsyncException

This shows how to catch the exceptions in an async method. This method is not a standard and need not hold good for debugging the exception. But it shows that it is possible to catch the exceptions that occur in async method.

ExpressionsAndTrees

Shows how to parse and traverse an expression tree in c#. It also shows how to use a delegate to create and call a method on the fly at the runtime.

ObserverPattern

Shows how Observer pattern is implemented in C# using the IObserver, IObservable and IDisposable interfaces. Basically Observable holds a list of Observers that subscribe to them and returns a Disposable to those observers so that when ever they want to unsubcribe, they can use the Disposable to unsubscribe.

ConstVsReadOnly

Shows the basic difference between a const and a readonly variable. The main difference is that const should be initialized in declaration, but readonly can be initialized in constructor as well.

About

Super crazy C# doubts resolved in code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages