Enum “Inheritance”

This is not possible. Enums cannot inherit from other enums. In fact all enums must actually inherit from System.Enum. C# allows syntax to change the underlying representation of the enum values which looks like inheritance, but in actuality they still inherit from System.enum. See section 8.5.2 of the CLI spec for the full details. Relevant … Read more

Equivalent of Math.Min & Math.Max for Dates?

There’s no built in method to do that. You can use the expression: (date1 > date2 ? date1 : date2) to find the maximum of the two. You can write a generic method to calculate Min or Max for any type (provided that Comparer<T>.Default is set appropriately): public static T Max<T>(T first, T second) { … Read more

C# getting the path of %AppData%

To get the AppData directory, it’s best to use the GetFolderPath method: Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) (must add using System if not present). %AppData% is an environment variable, and they are not automatically expanded anywhere in .NET, although you can explicitly use the Environment.ExpandEnvironmentVariable method to do so. I would still strongly suggest that you use GetFolderPath however, … Read more

Where Is Machine.Config?

32-bit %windir%\Microsoft.NET\Framework\[version]\config\machine.config 64-bit %windir%\Microsoft.NET\Framework64\[version]\config\machine.config [version] should be equal to v1.0.3705, v1.1.4322, v2.0.50727 or v4.0.30319. v3.0 and v3.5 just contain additional assemblies to v2.0.50727 so there should be no config\machine.config. v4.5.x and v4.6.x are stored inside v4.0.30319.

What is the difference between IQueryable and IEnumerable?

First of all, IQueryable<T> extends the IEnumerable<T> interface, so anything you can do with a “plain” IEnumerable<T>, you can also do with an IQueryable<T>. IEnumerable<T> just has a GetEnumerator() method that returns an Enumerator<T> for which you can call its MoveNext() method to iterate through a sequence of T. What IQueryable<T> has that IEnumerable<T> doesn’t … Read more

Better way to check if a Path is a File or a Directory?

From How to tell if path is file or directory: // get the file attributes for file or directory FileAttributes attr = File.GetAttributes(@”c:\Temp”); //detect whether its a directory or file if ((attr & FileAttributes.Directory) == FileAttributes.Directory) MessageBox.Show(“Its a directory”); else MessageBox.Show(“Its a file”); Update for .NET 4.0+ Per the comments below, if you are on … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)