C#/.NET Technical Questions Flashcards
What is a Class in C#?
A class is a blueprint for an object that defines what that object will look like. Think of it like a cookie cutter. You define classes with properties and methods, and then you can instantiate them as many times as you want (i.e. using the cookie cutter to make as many cookies as you want.)
What are Class Members?
Instance members - accessible from an object
Static members - accessible from the class
What is an Object?
An object is an instance of a class
Ex: JohnObject has a name, age, height, weight, can perform methods such as run, walk, talk, sleep, eat
Where in C# is it appropriate to use Camel Case?
Camel Case is appropriate when naming private or internals fields such as parameters and variables
What is an Access Modifier and why are they used?
It is a way to control access to a class and/or its members, and it creates safety in our programs, preventing bugs in our code.
In C# they include:
1. Public
2. Private
3. Protected
4. Internal
5. Protected Internal
What is OOP (Object Oriented Programming in relation to C#/.NET?
It’s a style of programming that uses objects to represent data in your code.
It’s four main concepts are:
* Encapsulation
* Inheritance
* Abstraction
* Polymorphism
What is Encapsulation?
Encapsulation refers to hiding data in private fields so that it’s harder to mess up.
Example: let’s imagine we had a class called Cohort that contained a list of students. We ONLY want to add a student to our list IF a) the cohort has less than 20 people and b) the student is approved for admission. If we make our list of students public, any developer in our code base can add any student, even if they don’t meet those conditions. If we make it private (i.e. if we ENCAPSULATE it in our Cohort class), we can write a public method that will add a student to a class only if our two conditions are met.
What is Inheritance?
Inheritance refers to inheriting fields and methods from one class to another.
Base Class(parent) - the class being inherited from.
Derived Class(child) - the class that inherits from another class
For example, we might make a Person base class and have Student and Instructor inherit from it so that we don’t have to write out all the same properties twice. This cuts down on the code we have to write and makes our code more reusable.
What is Abstraction?
It refers to a simple interface that does a complicated thing.
Example: in Entity Framework, we can write _context.Orders.ToList() and get a list of all our orders. Under the hood, Entity is writing a SQL query, reading the raw data, mapping it to our Order model, and adding it to a list. (We did all these things in ADO.NET!) We don’t have to see or think about all of that complexity, because Entity framework has abstracted it away.
What is Polymorphism?
Polymorphism means “many forms”. In OOP languages, classes and methods can occur in many forms. Example one: a Parrot class and a Toucan class can both implement a Bird interface in different ways, which means that the Bird interface occurs in many forms. A controller in ASP.NET can have two methods called Create, one that loads a create form and one that accepts data from a Create form. The create method occurs in many forms.
What is an ERD and why are they helpful?
ERD stands for entity relationship diagram. ERDs map the relationships between your tables in a database. They help the whole team get on the same page with data structure and provide a point of reference throughout the project.
What is the MVC design pattern?
MVC stands for Model, View Controller. We build MVC applications in ASP.NET, but a lot of frameworks use MVC. Models represent the tables in your database, views present that data to the user, and controllers are in charge of controlling the signal flow through the application– in our case, they accept HTTP requests from a client, query the database, map the data to our models, and then send it to the views
What experience do you have with SQL?
We used T-SQL (Microsoft’s specific flavor of SQL) with SQL Server. We primarily used SQL in tandem with ADO.NET, which is a database tool in .NET core and allowed us to write complex SQL queries to load data into our web applications.
What is RESTful API?
RESTful stands for Representational State Transfer. Generally, this means that the API is in charge of representing the current ‘state’ of the database to the client. (The state of the database just means what data is in there at the time of the request.) A RESTful API sends data back as JSON. (Some other API architectures, like SOAP, send data back as XML.)
There are some technical rules that an API is SUPPOSED to fulfill in order to be considered truly RESTful, but very few actually fulfill all of them. The rules are from a guy named Roy Fielding’s dissertation. Amaze your friends and control your enemies with this information.
How are namespaces used in C#?
Namespaces let us organize our code and divide it into distinct sections. A class name declared in one namespace wouldn’t conflict with a class named the same thing in another namespace. We can have nested namespaces (such as Bangazon.Models).
The using directive allows us to alias namespaces that are built into the .NET ecosystem. For example, every time we wanted to use a List we COULD type out the full name with its namespace:
System.Collections.Generic.List listOfStuff = new System.Collections.Generic.List();
But that’s a mouth full! Instead, we can add a using directive:
using System.Collections.Generic
And that allows us to “alias” everything in that namespace (it means we don’t have to type out the full thing and can can just start with the word List).
What are Razor Views?
Razor views use markup syntax to build HTML pages in C#/.NET. Razor views are an example of server-generated HTML, which means the C#/.NET code running on the server decides how the web page should look and what should be displayed and then sends a finished product to the server. In what we used, Razor Views were the “V” in MVC apps. (Model, View, Controller).
What is git?
Git is a hugely popular version control system. We used the git CLI (command line interface), which means we accesses git from our terminals.
What is Github?
GitHub is an online hosting platform for git repositories. GitHub is often used for open-source development.
What is a Single Page Application (and why is it more efficient)?
A single page application (SPA) is an app that uses JavaScript to change out content on the web page. In a SPA, there is only one HTML file. You’ve been building SPAs this whole time without knowing it!
What is Version Control?
Version control is a system to track changes in your code (also called “versions” of your code). Git is by far the most common version control system and it’s the one we used.