Goldman Sachs Interview Question
Applications DevelopersCountry: India
Can we override String class methods, we can create a new method for the concat function but interviewer asked for String's class concat method, we cannot do so as it is final. We cannot either overried any method or extend the class itself.
How about writing extension methods for string type?
- siva November 22, 2012static class StringExtensions
{
public static string CustomConcat(this string s, string s2)
{
return string.Concat(s, s2).ToUpper();
}
}
static void Main(string[] args)
{
string s = "abc";
s = s.CustomConcat("def");
}