CSharp
CSharp
A shallow copy of a collection is a copy of the collection structure, not the elements. With a shallow
copy, two collections now share the individual elements.
class A
{
public int a = 0;
public void display()
{
Console.WriteLine("The value of a is " + a);
}
}
class Program
{
static void Main(string[] args)
{
A ob1 = new A();
ob1.a = 10;
A ob2 = new A();
ob2 = ob1;
ob1.a = 5; // <-- If you see value of ob2.a after this line, it will be 5.
}
}
A deep copy of a collection is two collections with all of the elements in the original collection
duplicated.
class A
{
public int a = 0;
public void display()
{
Console.WriteLine("The value of a is " + a);
}
}
class Program
{
static void Main(string[] args)
{
A ob1 = new A();
ob1.a = 10;
A ob2 = new A();
ob2.a = ob1.a;
ob1.a = 5; // <-- If you see value of ob2.a after this line, it will be 10.
}
}
How can you sort the elements of the array in descending order?
By calling Array.Sort() and then Array.Reverse() methods
How to convert a sentence into Title Case (Capitalize first character of every word)?
Write a single line of code to create a text file and write contents into it.
Use following code
System.IO.File.WriteAllText(@"c:\MyTextFile.txt", "MyContents");
What is the best way to add items from an Array into ArrayList?
Use AddRange method of the ArrayList.
string[] arr = new string[] { "ram", "shyam", "mohan" };
arrList.AddRange(arr);
eg.
var age = 10;
Because the initialization value (10) of the variable age is integer type of age will be treated
as integer type of variable. There are few limitation of the var type of variables.
They are:
#. They can't be initialized as null.
#. They need to be declared and initialized in the same statement.
#. They can't be used as a member of the class.
#. They can’t be passed as an argument.
For example
var emp = new { Name = "Sheo", Gender = "Male", Active = true };
1. When the class itself is inherited from an abstract class, but not all base abstract methods
have been overridden.
2. When at least one of the methods in the class is abstract.
Object Pooling is something that tries to keep a pool of objects in memory to be re-used later
and hence it will reduce the load of object creation to a great extent.
Object Pool is nothing but a container of objects that are ready for use. Whenever there is a
request for a new object, the pool manager will take the request and it will be served by
allocating an object from the pool.
Strong name key is used to specify the strong name used to deploy any application in the
GAC (Global Assembly Catch) in the system.
Abbreviated as GAC, the Global Assembly Cache is a machine-wide store used to hold
assemblies that are intended to be shared by several applications on the machine. Each
computer where the common language runtime (CLR) is installed has a global assembly
cache. The global assembly cache stores the assemblies specifically designated to be shared
by several applications on the computer.
Partial class
Instead of defining an entire class, you can split the definition into multiple classes by using
the partial keyword. When the application is complied, the C# complier will group all the
partial classes together and treat them as a single class. There are a couple of good reasons to
use partial classes. Programmers can work on different parts of a class without needing to
share the same physical file. Also you can separate your application business logic from the
designer-generated code.
C#
Public partial class Employee
{}
{}
Arithmetic
+-*/%
String concatenation
+
Increment, decrement
++ --
Shift
<< >>
Relational
== != < > <= >=
Assignment
= += -= *= /= %= &= |= ^= <<= >>=
Member access
.
Indexing
[]
Cast
()
Conditional
?:
Object creation
new
Type information
as is sizeof typeof