The difference between Constructor and Method/Function are in the return value or no return value
Constructor doesn’t returns any value, just like create an instance of object
Example :
class Program
{
static void Main(string[] args)
{
weight(“Izu”, 55);
}
static void weight(string name, int kg)
{
Console.Write(“Name : “);
Console.WriteLine(nama);
Console.Write(“Weight: “);
Console.Write(kg);
Console.WriteLine(” Kg”);
}
}
}
Debug Output :
Name : Izu
Berat: 55
Function / Method has return value, just like to peform some operation
Example :
class Program
{
static string personal(string front, string back, string birthDate, string hobby)
{
string outpt;
outpt = front + ” ” + back + ” Data”;
Console.Write(“Full name \t—>”);
Console.WriteLine(front);
Console.Write(“Nick Name \t—>”);
Console.WriteLine(back);
Console.Write(“Birth Date \t—>”);
Console.WriteLine(birthDate);
Console.Write(“Hobby \t—>”);
Console.WriteLine(hobby);
return outpt;
}
static void Main(string[] args)
{
string x;
{
x = personal(“Izumi”, “Shota”, “16 Febuary”, “Drawing”);
Console.WriteLine(x);
}
}
}
}
Debug Output :
Full Name —>Izumi
Nick Name —>Shota
Birth Date —>16 Febuary
Hobby —>Drawing
Izumi Shota Data