In the following code I do not know what means " where S : new() " part. What is the keyword to find more info in Google ?
public virtual void Print<S, T>()
where S : new()
{
Console.WriteLine(default(T));
Console.WriteLine(default(S));
}
In C, all escape sequences consist of two or more characters, the first of which is the backslash, \ (called the "Escape character"); the remaining characters determine the interpretation of the escape sequence. For example, \n is an escape sequence that denotes a newline character.
%s and string We can print the string using %s format specifier in printf function. It will print the string from the given starting address to the null '\0' character. String name itself the starting address of the string. So, if we give string name it will print the entire string.
There's no new / delete expression in C.
The new()
constraint means that the particular generic parameter is required to have a default constructor (i. e. a constructor with no parameters).
The purpose of this is typically to allow you to type-safely construct new instances of generic parameter types without resorting to reflection/Activator.CreateInstance.
For example:
public T Create<T>() where T : new()
{
// allowed because of the new() constraint
return new T();
}
For more information, check out http://msdn.microsoft.com/en-us/library/sd2w2ew5%28v=vs.80%29.aspx.
As far as a google search term, I'd try "c# new() constraint".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With