Question 1:
For answer this please check below link.
Click here to see Answer
Question 2:
For answer this please check below link.
Click here to see Answer
Click here to see Answer
public class Person { public string Name { get; set; } } public class Program { private static void Main(string[] args) { var person1 = new Person { Name = "Test" }; Console.WriteLine(person1.Name);//Output:Test Person person2 = person1; person2.Name = "Shahrooz"; Console.WriteLine(person1.Name);//Output:Shahrooz person2 = null; Console.WriteLine(person1.Name);//Output:??? } }
Question 2:
public class MyClass { public void Func(Object a) { Console.WriteLine("Object"); } public void Func(String a) { Console.WriteLine("String"); } } public class Program { private static void Main(string[] args) { MyClass mc = new MyClass(); mc.Func(null); } }
Click here to see Answer
Click here to see Answer
+1 for this :)
ReplyDeletewhat is d answer of second one ?
ReplyDeleteAnswer of question no 2 is : "String"
Deleteas we passed null, Compiler always called the nullable parameter type first. if you have "int?" in parameter then it called those method. If you want to call the "object" method then you have to write "null as object".
DeleteAlso added link below question for more detail.
DeleteThis was lovelly to read
ReplyDelete