📝 What is an Abstract Class?
The
An Abstract class is a class which is denoted by
Abstract classes have the following features:
🔸 An abstract class cannot be instantiated.
🔸 An abstract class may contain abstract methods and accessors.
🔸 It is not possible to modify an abstract class with the sealed modifier because the two modifiers have opposite meanings. The
🔸 A non-abstract class derived from an abstract class must include actual implementations of all inherited abstract methods and accessors.
#post
The
abstract
modifier indicates that the thing being modified has a missing or incomplete implementation. The abstract modifier can be used with classes, methods, properties, indexers, and events.An Abstract class is a class which is denoted by
abstract
keyword and can be used only as a Base class.Abstract classes have the following features:
🔸 An abstract class cannot be instantiated.
🔸 An abstract class may contain abstract methods and accessors.
🔸 It is not possible to modify an abstract class with the sealed modifier because the two modifiers have opposite meanings. The
sealed
modifier prevents a class from being inherited and the abstract
modifier requires a class to be inherited.🔸 A non-abstract class derived from an abstract class must include actual implementations of all inherited abstract methods and accessors.
#post
What will be the output of the following code snippet?
Anonymous Quiz
4%
1 2 3 4 5
17%
11 12 13 14 15
78%
11 2 13 4 15
1%
1 3 5 7 9
📝 How to implement the Where method in C#?
The
The function returns an object that implements the
This is syntactic sugar introduced in C# 2.0. In earlier versions you had to create your own
#post
The
yield
keyword actually does quite a lot here. It creates a state machine "under the covers" that remembers where you were on each additional cycle of the function and picks up from there.The function returns an object that implements the
IEnumerable<T>
interface. If a calling function starts foreach
ing over this object, the function is called again until it "yields" result based on some predicate
.This is syntactic sugar introduced in C# 2.0. In earlier versions you had to create your own
IEnumerable
and IEnumerator
objects to do stuff like this.#post
#challenge
💻 Compounding Letters | #easy
Create a function that takes a string and returns a new string with each new character accumulating by +1. Separate each set with a dash.
Capitalize the first letter of each set.
Examples:
#interview
💻 Compounding Letters | #easy
Create a function that takes a string and returns a new string with each new character accumulating by +1. Separate each set with a dash.
Capitalize the first letter of each set.
Examples:
Accum("abcd") ➞ "A-Bb-Ccc-Dddd"🏆 Leave your solutions in the comments. The solution will be posted below in a couple of hours 👇
Accum("RqaEzty") ➞ "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy"
Accum("cwAt") ➞ "C-Ww-Aaa-Tttt"
#interview
📝 What is namespace in C#?
A namespace is designed for providing a way to keep one set of names separate from another. The class names declared in one namespace does not conflict with the same class names declared in another.
🔸 NET uses namespaces to organize its many classes.
🔸 Declaring your own namespaces can help you control the scope of class and method names in larger programming projects.
A namespace is designed for providing a way to keep one set of names separate from another. The class names declared in one namespace does not conflict with the same class names declared in another.
🔸 NET uses namespaces to organize its many classes.
🔸 Declaring your own namespaces can help you control the scope of class and method names in larger programming projects.
SampleNamespace#post
{
class SampleClass
{
public void SampleMethod()
{
System.Console.WriteLine(
"SampleMethod inside SampleNamespace");
}
}
}
📝 How can we check equality in .NET?
🔸 The
🔸 The
🔸 The
🔸 The
🔸 The comparison operator
#post
🔸 The
ReferenceEquals()
method - checks if two reference type variables(classes, not structs) are referred to the same memory address.🔸 The
virtual Equals()
method. (System.Object) - checks if two objects are equivalent.🔸 The
static Equals()
method - is used to handle problems when there is a null value in the check.🔸 The
Equals
method from IEquatable interface.🔸 The comparison operator
==
- usually means the same as ReferenceEquals, it checks if two variables point to the same memory address. The gotcha is that this operator can be override to perform other types of checks. In strings, for instance, it checks if two different instances are equivalent.#post
#challenge
💻 Letter Distance | #easy
Given two words, the letter distance is calculated by taking the absolute value of the difference in character codes and summing up the difference.
If one word is longer than another, add the difference in lengths towards the score.
To illustrate:
#interview
💻 Letter Distance | #easy
Given two words, the letter distance is calculated by taking the absolute value of the difference in character codes and summing up the difference.
If one word is longer than another, add the difference in lengths towards the score.
To illustrate:
"fly") = dist("h", "f") + dist("o", "l") + dist("u", "y") + dist(house.Length, fly.Length)Examples:
= |104 - 102| + |111 - 108| + |117 - 121| + |5 - 3|
= 2 + 3 + 4 + 2
= 11
LetterDistance("sharp", "sharq") ➞ 1🏆 Leave your solutions in the comments. The solution will be posted below in a couple of hours 👇
LetterDistance("abcde", "Abcde") ➞ 32
LetterDistance("abcde", "bcdef") ➞ 5
#interview
This media is not supported in your browser
VIEW IN TELEGRAM
📝 How we can pass parameters to a method?
There are three ways that parameters can be passed to a method:
🔸 Value parameters − This method copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument.
🔸 Reference parameters − This method copies the reference to the memory location of an argument into the formal parameter. This means that changes made to the parameter affect the argument.
🔸 Output parameters − This method helps in returning more than one value.
#post
There are three ways that parameters can be passed to a method:
🔸 Value parameters − This method copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument.
🔸 Reference parameters − This method copies the reference to the memory location of an argument into the formal parameter. This means that changes made to the parameter affect the argument.
🔸 Output parameters − This method helps in returning more than one value.
#post
What will be the output of the following code snippet?
Anonymous Quiz
62%
Hi, I am a Tech-savvy!!
23%
Error
11%
The program compiled successfully and nothing is printed
4%
None of the above
This media is not supported in your browser
VIEW IN TELEGRAM
📝 What are the benefits of a Deferred Execution in LINQ?
In LINQ, queries have two different behaviors of execution: immediate and deferred.
Deferred execution means that the evaluation of an expression is delayed until its realized value is actually required. It greatly improves performance by avoiding unnecessary execution.
Consider:
If you were to make LINQ fully execute each time, each operation (Select / Where) would have to iterate through the entire sequence. This would make chained operations very inefficient.
#post
In LINQ, queries have two different behaviors of execution: immediate and deferred.
Deferred execution means that the evaluation of an expression is delayed until its realized value is actually required. It greatly improves performance by avoiding unnecessary execution.
Consider:
results = collectionWith deferred execution, the above iterates your collection one time, and each time an item is requested during the iteration, performs the map operation, filters, then uses the results to build the list.
.Select(item => item.Foo)
.Where(foo => foo < 3)
.ToList();
If you were to make LINQ fully execute each time, each operation (Select / Where) would have to iterate through the entire sequence. This would make chained operations very inefficient.
#post
#challenge
💻 Pentagonal Number | #easy
Write a function that takes a positive integer num and calculates how many dots exist in a pentagonal shape around the center dot on the Nth iteration.
In the image below you can see the first iteration is only a single dot. On the second, there are 6 dots. On the third, there are 16 dots, and on the fourth there are 31 dots.
Return the number of dots that exist in the whole pentagon on the Nth iteration.
Examples:
#interview
💻 Pentagonal Number | #easy
Write a function that takes a positive integer num and calculates how many dots exist in a pentagonal shape around the center dot on the Nth iteration.
In the image below you can see the first iteration is only a single dot. On the second, there are 6 dots. On the third, there are 16 dots, and on the fourth there are 31 dots.
Return the number of dots that exist in the whole pentagon on the Nth iteration.
Examples:
pentagonal(1) ➞ 1🏆 Leave your solutions in the comments. The solution will be posted below in a couple of hours 👇
pentagonal(2) ➞ 6
pentagonal(3) ➞ 16
pentagonal(8) ➞ 141
#interview
📝 What are the different types of classes in C#?
The different types of class in C# are:
🔸 Partial class – Allows its members to be divided or shared with multiple .cs files. It is denoted by the keyword Partial.
🔸 Sealed class – It is a class which cannot be inherited. To access the members of a sealed class, we need to create the object of the class. It is denoted by the keyword Sealed.
🔸 Abstract class – It is a class whose object cannot be instantiated. The class can only be inherited. It should contain at least one method. It is denoted by the keyword abstract.
🔸 Static class – It is a class which does not allow inheritance. The members of the class are also static. It is denoted by the keyword static. This keyword tells the compiler to check for any accidental instances of the static class.
#post
The different types of class in C# are:
🔸 Partial class – Allows its members to be divided or shared with multiple .cs files. It is denoted by the keyword Partial.
🔸 Sealed class – It is a class which cannot be inherited. To access the members of a sealed class, we need to create the object of the class. It is denoted by the keyword Sealed.
🔸 Abstract class – It is a class whose object cannot be instantiated. The class can only be inherited. It should contain at least one method. It is denoted by the keyword abstract.
🔸 Static class – It is a class which does not allow inheritance. The members of the class are also static. It is denoted by the keyword static. This keyword tells the compiler to check for any accidental instances of the static class.
#post