cshar Flashcards
What is an object in C#?
An object is an instance of a class. A class can have as many instances as needed. For example, Honda Civic is an instance of a Car. In real programming, Honda Civic is an object. Therefore, Honda Civic is an instance of the class Car. The Model, Type, Color, and Size properties of the Honda Civic are Civic, Honda, Red, and 4, respectively. BMW 330, Toyota Carolla, Ford 350, Honda CR4, Honda Accord, and Honda Pilot are some more examples of objects of Car.
What is the difference between a struct and a class in C#?
Struct
The struct is a value type in C# and inherits from System.Value Type.
Struct is usually used for smaller amounts of data.
Struct can’t be inherited from other types.
A structure can’t be abstract.
No need to create an object with a new keyword.
Do not have permission to create any default constructor.
Class
The class is a reference type in C#, and it inherits from the System.Object Type.
Classes are usually used for large amounts of data.
Classes can be inherited from other classes.
A class can be an abstract type.
We can create a default constructor.
What is the difference between Interface and Abstract Class in C#?
A class can implement any number of interfaces, but a subclass can, at most, use only one abstract class.
An abstract class can have non-abstract methods (concrete methods), while in the case of interface, all the methods have to be abstract.
An abstract class can declare or use any variables, while an interface cannot do so.
In an abstract class, all data members or functions are private by default, while in an interface, all are public; we can’t change them manually.
In an abstract class, we need to use abstract keywords to declare abstract methods; in an interface, we don’t need that.
An abstract class can’t be used for multiple inheritance, while the interface can be used for multiple inheritance.
An abstract class uses a constructor, while we don’t have any constructor in an interface.
What is an enum in C#?
An enum is a value type with a set of related named constants, often called an enumerator list. The enum keyword is used to declare an enumeration. It is a primitive data type that is user-defined.
An enum type can be an integer (float, int, byte, double, etc.). But if you use it beside int, it has to be cast.
An enum is used to create numeric constants in the .NET framework. All the members of the enum are enum type. Therefore, there must be a numeric value for each enum type.
The underlying default type of the enumeration element is int. By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1.
enum Dow {Sat, Sun, Mon, Tue, Wed, Thu, Fri};
C#Copy
Some points about enum,
Enums are enumerated data types in c#.
Enums are not for the end-user. They are meant for developers.
Enums are strongly typed constant. They are strongly typed, i.e., an enum of one type may not be implicitly assigned to an enum of another type even though the underlying value of their members is the same.
Enumerations (enums) make your code much more readable and understandable.
Enum values are fixed. Enum can be displayed as a string and processed as an integer.
The default type is int, and the approved types are byte, sbyte, short, ushort, uint, long, and ulong.
Every enum type automatically derives from System.Enum, and thus, we can use System.Enum methods on enums.
Enums are value types created on the stack, not the heap.
What are Properties in C#?
In C#, a property is a member of a class that provides a way to read, write or compute the value of a private field. It exposes a public interface to access and modify the data stored in a class while allowing the class to maintain control over how that data is accessed and manipulated.
Properties are declared using the get and set accessors, which define the behavior for getting or setting the property value. The get accessor retrieves the value of the property, while the set accessor sets the value of the property. A property can have one or both accessors, depending on whether it is read-only, write-only, or read-write.
For example, consider a Person class with a private field name. Then, a property Name can be created to provide access to this field like this.
void static public
Public declared variables can be accessed from anywhere in the application. Static declared variables can be accessed globally without needing to create an instance of the class. Void is a type modifier which states the method and is used to specify the return type of a method in C#.
using
The ‘using’ statement can be used in order to obtain a resource for processing before automatically disposing it when execution is completed.
serialisation
In order to transport an object through a network, we would need to convert it into a stream of bytes. This process is called Serialization.
Name all the C# access modifiers.
Private Access Modifier - A private attribute or method is one that can only be accessed from within the class.
Public Access Modifier - When an attribute or method is declared public, it can be accessed from anywhere in the code.
Internal Access Modifier - When a property or method is defined as internal, it can only be accessible from the current assembly point of that class.
Protected Access Modifier - When a user declares a method or attribute as protected, it can only be accessed by members of that class and those who inherit it.
What is meant by a Partial Class?
A partial class effectively breaks a class’s definition into various classes in the same or other source code files. A class definition can be written in numerous files, but it is compiled as a single class at runtime, and when a class is formed, all methods from all source files can be accessed using the same object. The keyword ‘partial’ denotes this.
sealed cla
When a restriction needs to be placed on the class that needs to be inherited, sealed classes are created. In order to prevent any derivation from a class, a sealed modifier is used. Compile-time error occurs when a sealed class is forcefully specified as a base class.
What is the difference between Arraylist and Array?
An array only has items of the same type and its size if fixed. Arraylist is similar but it does not have a fixed size.
what is javascript
JavaScript is a popular web scripting language that’s used for client-side and server-side development. JavaScript can be inserted into HTML pages and executed by web browsers.
Apart from web development, it’s used in mobile app development, game development, querying databases, and more.
List Some Key Features of JavaScript.
Lightweight interpreted language with object-oriented programming (OOP)
Dynamically-typed
Platform-independent
Offers client-side validation
How Is JavaScript Different From Java?
While they share some letters in their names, they are not interlinked and are designed for different purposes. While Java is an OOP language, JavaScript is an OOP script. This means that JavaScript is written in text and then interpreted, and Java is compiled. In terms of apps, Java is used to create apps on devices or browsers, and JavaScript is mainly used with HTML documents and browsers.
comments
For a single line of comment, you use two forward slash symbols (//) (/**/)
The Difference Between Undeclared & Undefined Variables?
An undeclared variable has not been declared anywhere in the code, so said variable does not exist. If you try to read an undeclared variable, JavaScript throws an error.
An undefined variable has been declared in the program, but no value has been assigned. This means the variable exists, but its value is yet to be defined.