Visual Studio IDE free copy using ALT

I just wanted to copy that code without the comments. So, the trick is to simply press the Alt button, and then highlight the rectangle you like.(e. g. below).

protected void MyCommand(string e)
    {
        //if (e == "Hello")
        //{
        //    lblFog.Text = e.CommandArgument.ToString();
        //}
    }

In the above code if I want to select :

if (e == "Hello")
{
    lblFog.Text = e.CommandArgument.ToString();
}

Then I press ALt key and select the rectangle and no need to uncomment the lines.

Define data type for enums

The data type can be defined for an enumeration:

enum EnumName : [byte, char, int16, int32, int64, uint16, uint32, uint64]
{
    A = 1,
    B = 2
}

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 information from the spec

  • All enums must derive from System.Enum
  • Because of the above, all enums are value types and hence sealed

Source:
http://stackoverflow.com/questions/757684/enum-inheritance/757762#757762

Object size in memory c#

Unfortunately there is no direct way to do it. Speacialy for the managed code. May you can use memorystream and serialization for getting an idea but this are not actual size of your object. You may use some solution below for calculation actual size.

GC
One way is to use the GC.GetTotalMemory method to measure the amount of memory used before and after creating your object. This won’t be perfect, but as long as you control the rest of the application you may get the information you are interested in.
Source :http://stackoverflow.com/questions/605621/how-to-get-object-size-in-memory

Using Strike or SOS Debugging Extension (SOS.dll)
use : DumpHeap [-stat] [-min <size>][-max <size>] [-thinlock] [-mt <MethodTable address>] [-type <partial type name>][start [end]]

Displays information about the garbage-collected heap and collection statistics about objects.
The DumpHeap command displays a warning if it detects excessive fragmentation in the garbage collector heap.
The -stat option restricts the output to the statistical type summary.
The -min option ignores objects that are less than the size parameter, specified in bytes.
The -max option ignores objects that are larger than the size parameter, specified in bytes.
The -thinlock option reports ThinLocks. For more information, see the SyncBlk command.
The -mt option lists only those objects that correspond to specified the MethodTable structure.
The -type option lists only those objects whose type name is a substring match of the specified string.
The start parameter begins listing from the specified address.
The end parameter stops listing at the specified address.

!dumpheap -stat
Note that !dumpheap only gives you the bytes of the object type itself, and doesn’t include the bytes of any other object types that it might reference

More Info:
http://msdn.microsoft.com/en-us/library/bb190764.aspx

3rd party solutions

Using .Net Memory Profiler (Easy way)
http://memprofiler.com/download.aspx

using CLR Profiler (free)
http://www.microsoft.com/downloads/details.aspx?familyid=A362781C-3870-43BE-8926-862B40AA0CD0&displaylang=en

ANTS Memory Profiler
http://www.red-gate.com/products/ants_memory_profiler/index.htm

Note:
Some people have confused the System.Runtime.InteropServices.Marshal.SizeOf() service with this API.  However, Marshal.SizeOf reveals the size of an object after it has been marshaled.  In other words, it yields the size of the object when converted to an unmanaged representation.  These sizes will certainly differ if the CLR’s loader has re-ordered small fields so they can be packed together on a tdAutoLayout type.
source : http://blogs.msdn.com/cbrumme/archive/2003/04/15/51326.aspx

code bye…

How to set a default property for your class

I’m sorry but that functionality which is known by vb developers couldn’t possible when you are codding in c# .
Also there are some other solutions but its not possible to set a default property for your your class.

you can use indexer but its not that we want:

public string this[int idx]
{
get { … }
set { … }
}

or you can overload  implicit operator to do this but  is also not suggested.


[System.Diagnostics.DebuggerDisplay("{Value}")]
public class MyClass
{

public string Value { get; set; }
    public static implicit operator MyClass(string s)
    {
        return new MyClass { Value = s };
    }

    public static explicit operator string(MyClass f)
    {
        return f.Value;
    }
    public override string ToString()
    {
        return Value;
    }
}