WHAT ARE PARTIAL CLASSES
what are partial classes?
what are the advantages or uses of partial classes?
where are partail classes used?
Partial classes allows us to split class into 2 or more files. All these parts are then combined into a single class, when the application is compiled. the partial keyword can also be used to split a struct or an interface over two or more files.
DIFFERENCE BETWEEN SYSTEM.STRING AND SYSTEM.TEXT.STRINGBUILDER
System.String is immutable ||| StringBuilder is Mutable
As StringBuilder objects are mutable, they offer better performance than string objects of type
System.String, when heavy string manipulation is involved.
EXAMPLE OF SYSTEM.STRING I.E STRING() METHOD
Stack and Heap
string c#
vidoe
tutorial
for
beginners
EXAMPLE OF SYSTEM.TEXT.STRINGBUILDER
Stack and Heap
string c# video tutorial for beginners
using System;
using System.Text;
namespace ConsoleApplication4
{
public class MainClass
{
public static void Main()
{
string userString = string.Empty;
for(int i = 1; i <= 10000;i++ )
{
userString += i.ToString() + ” “;
}
Console.WriteLine(userString);
Console.ReadLine();
// using system.string
//string userstring = “C#”;
//userstring += “Vidoe”;
//userstring += “Tutorail”;
//userstring += “for”;
//userstring += “Beginners”;
//Console.WriteLine(userString);
//Console.ReadLine();
//// using system.text.stringbuilder
//StringBuilder userString = new StringBuilder(“C#”);
//userString.Append(” Video”);
//userString.Append(” Tutorial”);
//userString.Append(” For”);
//userString.Append(” Beginners”);
//Console.WriteLine(userString.ToString());
//Console.ReadLine();
}
}
}
DIFFERENCE BETWEEN CONVERT.TOSTRING() AND TOSTRING()
Convert.Tostring() handles null, while ToString() doesn’t and throws a NULL
Reference exception.
Depending on the type of the application architecture and what you are trying to achieve ,
you choose one over the other.
using System;
namespace ConsoleApplication4
{
public class MainClass
{
public static void Main()
{
Customer C1 = null;
string str = Convert.ToString(C1);
Console.WriteLine(str);
Console.ReadLine();
}
}
public class Customer
{
public string Name { get; set; }
}
}
WHY SHOULD YOU OVERRIDE EQUALS METHOD
1. WHAT IS EQUALS METHOD
2. WHY SHOULD YOU OVERRIDE IT.
using System;
namespace ConsoleApplication4
{
public class MainClass
{
public static void Main()
{
Customer C1 = new Customer();
C1.FirstName = “Malla”;
C1.LastName = “Gurram”;
Customer C2 = new Customer();
C2.FirstName = “Malla”;
C2.LastName = “Gurram”;
Console.WriteLine(C1 == C2);
Console.WriteLine(C1.Equals(C2));
Console.ReadLine();
}
}
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public override bool Equals(object obj)
{
if(obj == null)
{
return false;
}
if(!(obj is Customer))
{
return false;
}
return this.FirstName == ((Customer)obj).FirstName &&
this.LastName == ((Customer)obj).LastName;
}
public override int GetHashCode()
{
return this.FirstName.GetHashCode() ^ this.LastName.GetHashCode();
}
}
}
namespace ConsoleApplication4
{
public class MainClass
{
public static void Main()
{
Customer C1 = new Customer();
C1.FirstName = “Malla”;
C1.LastName = “Gurram”;
Customer C2 = new Customer();
C2.FirstName = “Malla”;
C2.LastName = “Gurram”;
Console.WriteLine(C1 == C2);
Console.WriteLine(C1.Equals(C2));
Console.ReadLine();
}
}
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public override bool Equals(object obj)
{
if(obj == null)
{
return false;
}
if(!(obj is Customer))
{
return false;
}
return this.FirstName == ((Customer)obj).FirstName &&
this.LastName == ((Customer)obj).LastName;
}
public override int GetHashCode()
{
return this.FirstName.GetHashCode() ^ this.LastName.GetHashCode();
}
}
}