In this code snippet, will see how to use method output parameters in C#. The output parameter works by passing in a reference of the variable you provide. It is very similar to the ref keyword. You put the out keyword in front of the parameter you want to use as an “output”. The method can still have a data type and return a value as the output parameter isn’t really outputting anything but is rather accessing the variable you passed it via reference.
In this code snippet, we’ll take a look at anonymous methods in C#. Anonymous methods don’t have names(obviously). They can be defined with the delegate keyword or by using the lambda expression. They can then be put into a variable of type delegate.
In this code snippet, we’ll find out what the abstract keyword does in C#. Classes and their members such as methods, properties, … that are marked with abstract keyword aren’t fully implemented. Abstract classes aren’t meant to be instantiated but are only meant to be inherited from. This means that class members(methods, properties, …) marked with the abstract keyword must be implemented in the child class.
In this code snippet, we’ll take a look at queues and stacks in C#. Stacks and queues are similar to lists in the way that they don’t require their size to be declared on creation and elements can be dynamically added or removed. In fact, all of the above(queues, stacks, and lists) are part of the same collections namespace and they implement some of the same interfaces.
In this code snippet, we’ll find out how to use lists in C#. Lists are similar to arrays, but unlike arrays, you can add and remove items from lists without having to destroy the entire list and making a new one. Also, lists have a lot of useful methods such as find(), exists(), sort(), … You can use intellisense in Visual Studio to explore all the methods available.
In this code snippet, we’ll take a look at dictionaries in C#.
Dictionaries can hold a collection of objects and are similar to lists. But unlike lists, the objects stored in the dictionary are paired with a key. That key can be used to access the object in the collection.
In this code snippet, we’ll find out how to iterate with the for, foreach, while and do while loop. What loops do is execute the code in their curly brackets(multiple times, maybe only once or even never). The number of times that they will do that depends on the condition that will get evaluated at the beginning of each iteration. Usually, the condition consists of the maximum number of iterations and the counter variable which contains the number of iterations so far. The counter is an integer that gets increased at the end of the loop. This way we can keep track of how many iterations were performed.
In this code snippet, we’ll find out what the unchecked keyword does in C#. The unchecked keyword is used to suppress arithmetic overflow exceptions. We will try to add two integers whose sum will exceed the size of the integer data type. This will cause an overflow to occur. The overflow would normally throw an exception, but if we wrap the expression with unchecked the exception will get suppressed and the integer will just overflow.
In this post, we’ll learn how to copy an array in Javascript. In Javascript, if you assign an array to another array using the = assignment operator you won’t actually copy the values from one array into the other. What you will do is make another reference to the first array, so now you just have to variables pointing at the same array.
This post contains a list Javascript code snippets. In the code snippets, you can find Javascript related topics with a quick explanation and a code example. I made this collection of code snippets so that if I ever forget something I can just come here to refresh my memory.