concept default in category c#

appears as: default, default, The default, defaults
C# in Depth

This is an excerpt from Manning's book C# in Depth.

Listing 3.4. Comparing a given value to the default in a generic way
static int CompareToDefault<T>(T value) where T : IComparable<T> { return value.CompareTo(default(T)); } ... Console.WriteLine(CompareToDefault("x")); Console.WriteLine(CompareToDefault(10)); Console.WriteLine(CompareToDefault(0)); Console.WriteLine(CompareToDefault(-10)); Console.WriteLine(CompareToDefault(DateTime.MinValue));

An optional parameter can be of any type, but there are restrictions on the default value specified. You can always use constants: numeric and string literals, null, const members, enum members, and the default(T) operator. Additionally, for value types, you can call the parameterless constructor, although this is equivalent to using the default (...) operator anyway. There has to be an implicit conversion from the specified value to the parameter type, but this must not be a user-defined conversion. Table 13.1 shows some examples of valid parameter lists.

Dependency Injection in .NET

This is an excerpt from Manning's book Dependency Injection in .NET.

By default, you can consider most (but not all) types defined in the BCL as safe, or STABLE DEPENDENCIES—I call them stable because they’re already there, tend to be backwards compatible, and invoking them has deterministic outcomes.

When a class has a good LOCAL DEFAULT, but we still want to leave it open for extensibility, we can expose a writable property that allows a client to supply a different implementation of the class’s DEPENDENCY than the default.

It would be tempting to make that implementation the default used by the class under development. However, when such a prospective default is implemented in a different assembly, using it as a default would mean creating a hard reference to that other assembly, effectively violating many of the benefits of loose coupling described in chapter 1.

Figure 6.19. Dependency graph generated by NDepend for Mary’s commerce solution. By default, NDepend includes all DEPENDENCIES, including modules from the BCL. The size of the boxes reflects the number of code lines in each module, and the thickness of the arrows reflects the number of members used across the references.
ASP.NET 4.0 in Practice

This is an excerpt from Manning's book ASP.NET 4.0 in Practice.

Figure 1.10. A Web Form with validator controls. As you can see, the validator generates a warning (displayed in red, by default) and blocks the form from being submitted.

A personalized error page is way more professional than a default one, and it’ll help you to protect sensitive data. Even though it’s useful to know as much as you can about your environment while you’re developing or debugging, an attacker can use this information to bypass your security check, to inspect your code, or, at worst, to arbitrarily execute some hidden functions.

As with previous threats, the problem is in how string concatenations are performed. A web server is protected by default from this attack (also known as directory traversal vulnerability). If you have your code inside a physical directory named c:\inetpub\ mysite\ and you’re requesting something like http://localhost/../../somefile.txt, the corresponding physical request won’t be processed. The problem isn’t in how the web server is processing these requests, but in how you dynamically compose a path. The path canonicalization issue surfaces in these scenarios.