Overloaded operators work with user defined or basic data type depending upon the type of operands. It gives the ability to use the same operator to do various functionality. Operator overloading allows the user to give additional meaning to most operators so that it can be used with the user'sown data types, thereby making the data type easier to use.
Tuesday, October 29, 2019
Sunday, October 27, 2019
Things To Remember
- Default Members
Members | Default Member | Allowed Declared accessibility of the member |
---|---|---|
enum | public | None |
Class | private | public, protected, internal, private, protected internal |
interface | public | None |
struct | private | public, private, internal |
Sunday, October 20, 2019
Difference between IEnumerable and IEnumerator
IEnumerable and IEnumerator both are interface.
Syntax are different but output are same.
In the above code value is iterating over while loop till "Thursday" value and then after iterate the value to the second method i.e, "EnumeratorWeekSecond".
Relation
IEnumerable is simply a list and having one method called GetEnumerator() which gets the another type of interface called IEnumerator.Syntax
Lets check the first demonstration of code.
IEnumerable
In the above code we simply create a list of weeks and iterate it over the foreach loop.
Then following are the output.
In the above code we simply create a list of weeks and iterate it over the MoveNext() method.
Then the following output are
Syntax are different but output are same.
How Enumerator are used over Enumerable?
In some cases we don't need to iterate over each and every value of collection object but we want to iterate some value in this collection object and remaining values will iterate over second business logic.
Let take an example for this.
In the above code value is iterating over while loop till "Thursday" value and then after iterate the value to the second method i.e, "EnumeratorWeekSecond".
Saturday, October 19, 2019
Difference between boxing and unboxing
Boxing: It is explicit conversion. It is a process of converting the value type to reference type.
For Eg: int, bool is a value type which is used to convert the reference type
Boxing value is stored in heap
UnBoxing: It is implicit conversion. It is a process of converting the reference type to value type.
For Eg: object is a reference type which is used to convert the value type
Tuesday, October 15, 2019
How Ref is different from Out parameter in C#?
Ref and Out both are used to pass the argument through the methods. The only main difference between these two are initialization. 'Ref' Keyword must have initialize the value or object before calling the function and in 'Out' Keyword there is not necessary to initialize before calling but it must be initialized in called method
The Ref keyword gave us the compile time error because as it doesn't have initialized when it is calling. In case of Out we must need to initialized the value in called method before any operation take place.
Example
In this example two methods are called in the main function. In one method have ref keyword and in other have out keyword.The Ref keyword gave us the compile time error because as it doesn't have initialized when it is calling. In case of Out we must need to initialized the value in called method before any operation take place.
Tuesday, October 8, 2019
Difference between Primary Key and Foreign Key
Primary key and foreign key are the two constraint which are used to uniqueness of data in sql. Primary key creates the identity of each one row and foreign key defines the relation between the two table.
Suppose create a book and customer table which is given below
Now insert the record in both the table. Remember one thing while inserting the record the value of book_id in customer table is same as the book_id in Book table.
Then select the both the table and analyze the result.
Analyse
Customer 1, 3, 5 have Book_A.
Customer 2 have Book_B
Customer 4 have Book_C
Suppose create a book and customer table which is given below
Now insert the record in both the table. Remember one thing while inserting the record the value of book_id in customer table is same as the book_id in Book table.
Then select the both the table and analyze the result.
Analyse
Customer 1, 3, 5 have Book_A.
Customer 2 have Book_B
Customer 4 have Book_C
Comparison Table
Primary Key | Foreign Key |
---|---|
A table can have a single primary key column. | A table can have more than one foreign key column. |
A table can't have two same value of primary key in a column. | A table can have a same value of foreign key in a column. |
Primary key doesn't allow us a null value. | Foreign key can contain a null value. |
For dropping the table or constraints, Primary key table must have to remove the references of foreign of the same table. | Foreign key table can be removed happily table or constraint. |
Saturday, October 5, 2019
Difference between Constant and Read-Only
Constant
Constant is known as "const" keyword which is known at compile time. It is the constant variable which needs to be assigned at the time of declaring the variable. It's value cannot changed after that when it assigned.
ReadOnly
Readonly is known as "readonly" keyword which is known at compile time and run time. It is the constant variable which is initialized either can be declaration or at the constructor of the same class.
Comparison Chart
Constant | Read-Only |
---|---|
Constant is used to declare fields or local variable. | Read-Only is used to declare fields. |
Constant can be computed at only compile time. | Read-Only can be computed at compile as well as run time. |
Constant can be assigned only at the time of declaration. | Read-Only can be assigned either at the time of declaration or runtime when object is initialized. |
Constant is implicitly static and the value cannot be changed through out the program. | Read-Only can be changed at runtime only in non static constructor. |
Friday, October 4, 2019
Difference between Abstract and Interface class
Abstract | Interface |
---|---|
An abstract is a class in which abstract as well as non extract member are present. | While in interface all the method must have to be abstract. |
An abstract class can declare or use any variables | In interface it is not allowed to do so. |
An abstract all functions are private by default. | While in interface all functions are public. |
In this, we must use a word 'abstract' to declare abstract method. | In interface we don't need to use that. |
This class can't be used for multiple inheritance. | Interface can be used as multiple inheritance. |
An abstract class have constructor. | In interface, we don't have any constructor. |
An abstract class can inherit only one abstract class. | Interface class can implement any number of interface. |
Wednesday, October 2, 2019
Difference between Struct and Class
Struct | Class |
---|---|
The Struct is a value type. | Class is a reference type. |
Struct is usually for small amount of data. | Class is usually for large amount of data. |
Struct type are used in stack memory. | Class type are used in heap memory. |
Struct can't be inherited from other type. | Class can be inherited from other type. |
Struct can't be abstract. | Class can be abstract. |
No need to create object by new keyword. | We can't use the object of a class by using new keyword. |
Don't have any default constructor or destructor. | We can create a default constructor or destructor. |
Struct can't be the protected data member. | Class can be the protected data member. |
Subscribe to:
Posts (Atom)