2010-01-25

typeof() GetType() is

Suppose there are three Classes(type) Aninaml, Dog and Tree
and 3 instances animal dog and tree

if(dog is Animal) // true
dog.GetType() == typeof(Dog) // true

call to GetType gets resolved at runtime, while typeof is resolved at compile time.

throw ex 和 throw 一样么?

不一样,
throw 是输出整个stacktrack,考虑多层设计中,UI层有try catch, 逻辑层有 try catch, 数据层有try catch, 三者均使用 throw, 假设是在数据层出错,输出的exception 信息会显示这三层的throw point,由此可以知道 exception的源头在数据层;如果是在逻辑层出错,会输出两层的 throw point, 由此可知 exception 的源头在逻辑层
但是用 throw ex的话,会清空stacktrace,如上例,你只能看到UI层的exception,无法获知到底是发生在UI层还是逻辑层还是数据层

因此,总是使用throw 抛出原始 exception

JIT and NGEN

JIT, Just in time,即时编译,每次运行都会进行,会对代码进行优化
NGEN Native image generator,在运行前一次性的把代码转换为本地代码并存储为本地文件,会改善程序的启动性能,但对总体的性能,有可能提升,也有可能降低

Assembly.LoadFile() Assembly.LoadFrom() Assembly.Load()

1、Assembly.LoadFile()只载入相应的dll文件,比如Assembly.LoadFile(”a.dll”),则载入a.dll,假如a.dll中引用了b.dll的话,b.dll并不会被载入。Assembly.LoadFrom则不一样,它会载入dll文件及其引用的其他dll,比如上面的例子,b.dll也会被载入。
2、用Assembly.LoadFrom()载入一个Assembly时,会先检查前面是否已经载入过相同名字的Assembly,比如a.dll有两个版本(版本1在目录1下,版本2放在目录2下),程序一开始时载入了版本1,当使用Assembly.LoadFrom(”2″”a.dll”)载入版本2时,不能载入,而是返回版本1。Assembly.LoadFile的话则不会做这样的检查,比如上面的例子换成Assembly.LoadFile的话,则能正确载入版本2。

3、Assembly.Load()方法参数为程序集的名称不包含扩展名

.net 4.0 中只保留了LoadFrom() 方法

http://msdn.microsoft.com/en-us/library/ee191568(VS.100).aspx


http://blog.csdn.net/nanqingfei/archive/2009/10/12/4659004.aspx

一个有用的C# Attribute: DebuggerDisplay


namespace ConsoleApplication2
{
[DebuggerDisplay("count ={Count}")]
public class Test
{
public int Count{ get; set;}
public string Name { get; set; }
public void Clear()
{
}
}
}


如上代码示例所示,该属性可以让对象在鼠标悬停时按格式显示Count字段的值,而不必点开对象查找,当对象有非常多的Property时,这个属性尤其有用

2009-12-30

Opera 常用快捷键

Standard keys
MovementMove one line up ↑
Move one line down ↓
Move one character to the right →
Move one character to the left ←
Move one screen-full up Page Up
Shift + Space
Move one screen-full down Page Down
Space
Move one screen-full to the left Ctrl + Page Up
Move one screen-full to the right Ctrl + Page Down
Go to top Home
Go to bottom End

FocusCycle focus forward within active context Tab
Cycle focus backward within active context Shift + Tab
Activate Enter
Exit context or cancel Esc
Display context (right-click) menu Shift + F10
Properties dialogue Alt + Enter

System keysOpen file Ctrl + O
Save copy of page Ctrl + S
Print page Ctrl + P
Hide Opera Ctrl + Alt + Shift + H

Text keys
EditingUndo recent changes Ctrl + Z
Redo recent changes Ctrl + Y
Ctrl + Shift + Z
Copy selection to clipboard Ctrl + C
Ctrl + Insert
Move selection to clipboard Ctrl + X
Shift + Delete
Paste from clipboard Ctrl + V
Shift + Insert
Copy selected text to "Notes" panel Ctrl + Shift + C
Select all Ctrl + A
Delete selection (or character right of cursor) Delete
Delete selection (or character left of cursor) Backspace
Toggle text-style bold Ctrl + B
Toggle text-style italic Ctrl + I
Toggle text-style underline Ctrl + U
Convert hex to Unicode Ctrl + Shift + X

FindFind text Ctrl + F
Find next instance of text Ctrl + G
F3
Find previous instance of text Ctrl + Shift + G
Shift + F3
Search for text in page (press F9 first to set focus on page) (numeric) /
. (period)
Search for text in links in page (press F9 first to set focus on page) Shift + (numeric) /
, (comma)

Loading keys
AccessGo to your home page Ctrl + Space
Alt + Home
Enter a Web address F2
Paste and go in current or new tab Ctrl + Shift + V
Speed Dial Ctrl + 0-9
Enter nickname for fast bookmark access Shift + F2
Save page address as new bookmark Ctrl + D
Save as new bookmark in active bookmark folder Ctrl + Shift + D

TransmissionReload (get latest version of) page Ctrl + R
F5
Reload selected frame Alt + F5
Ctrl + Shift + R
Stop page loading Esc
Cancel current voice prompt Esc

Navigation keys
HistoryGo to next page in history Alt + →
Ctrl + →
Shift + Backspace
Go to previous page in history Alt + ←
Ctrl + ←
Backspace
Fast Forward Shift + Backspace
Space

Site navigation

To remove the last part of any Web address (such as a sub-directory) and go to that address, press Ctrl + Backspace.
Display modesPrint preview (toggles on/off) Ctrl + Shift + P
Use entire screen for browsing F11
Toggle "Fit to width" Ctrl + F11

SourceView page source Ctrl + U
View source of active frame Ctrl + Shift + U
Validate source of active page or frame Ctrl + Alt + Shift + U

Developer ToolsOpen developer tool Ctrl + Shift + I

ZoomingIncrease zoom % by steps of 10 Plus
Ctrl + Plus
Decrease zoom % by steps of 10 Minus
Ctrl + Minus
Restore zoom to 100% *
Ctrl + 0

Link keysSelect next link in page Ctrl + ↓
Select previous link in page Ctrl + ↑
Follow selected link Enter
Open selected link in new tab Shift + Enter
Open selected link in background tab Ctrl + Shift + Enter
Save link target (such as document or image) Ctrl + Shift + S

Spatial navigation keysNavigate between links and form elements Shift + ← ↑ → ↓


Tip: The combination of the Shift key and arrow keys is the fastest way of moving around a Web page when wanting to locate links and Web form elements.
Form keysLog in/auto-fill form using the Wand Ctrl + Enter
Go to next element in form Tab
Go to previous element in form Shift + Tab
Select form element Space
Enter

Access keys

These shortcuts are unique to pages that have access keys enabled. Toggle HTML access keys Shift + Esc
Enter HTML access keys A-Z and 0-9

Page keys: basicsBrowse in new tab Ctrl + T
Close active tab Ctrl + W
Ctrl + F4
Undo closing of tab Ctrl + Shift + T

Application windowsBrowse in new application window Ctrl + N
Close application window Ctrl + Shift + W
Alt + F4

Tab keys: switchingCycle to next tab (defaults to recently used order) Ctrl + Tab
Cycle to previous tab (defaults to recently used order) Ctrl + Shift + Tab
Switch to previous tab on tab bar Ctrl + Shift + F6
Switch to next tab on tab bar Ctrl + F6

Panel keys: activationToggle last active panel with panel selector F4
Toggle last active panel Shift + F4
Activate panels for keyboard navigation F7
Expand all folders/views in panel Shift + →
Collapse all folders/views in panel Shift + ←
Open "Search" panel Ctrl + Shift + 1
Open "Bookmarks" panel Ctrl + Shift + 2
Ctrl + B
Open "Mail" panel Ctrl + Shift + 3
Open "Contacts" panel Ctrl + Shift + 4
Open "Chat" panel Ctrl + Shift + 5
Open "Notes" panel Ctrl + Shift + 6
Open "Transfers" panel Ctrl + Shift + 7
Open "History" panel Ctrl + Shift + 8
Ctrl + H
Open "Links" panel Ctrl + Shift + 9
Open "Windows" panel Ctrl + Shift + 0

Panel keys: actions
BookmarksOpen bookmark Enter
Open bookmark in new tab Shift + Enter
Open bookmark in background tab Ctrl + Shift + Enter

MailMark all e-mail in selected view as read Ctrl + Shift + A

ContactsShow messages associated with contact Enter
Compose message to contact Shift + Enter

TransfersOpen transferred file Enter

PreferencesEdit your preferences Alt + P
Ctrl + F12
Quickly edit most popular preferences F12
Edit browser appearance Shift + F12

Focus keysSet focus to Web page (to enable keyboard navigation) F9
Set focus to address field F8
Ctrl + L
Alt + D
Set focus to search field Ctrl + E
Set focus to personal bar (only when you have search fields) Shift + F7
Restore original address in address field and set focus to page Esc

Manager pagesManage bookmarks Ctrl + Shift + B
Manage transfers Ctrl + J
Manage history Ctrl + Shift + H
Manage links Ctrl + Shift + L

E-mail keys: reading and sending
BasicsCheck e-mail Ctrl + K
Write new message Ctrl + M
Attach files to message Ctrl + O
Upload queued messages to mail server Ctrl + Shift + K
Send composed message Ctrl + Shift + S
Ctrl + Enter

NavigationGo to next message J
Go to previous message U
Go to next unread message H
Shift + J
Go to previous unread message Y
Shift + U
Move one screen-full up Shift + Space
Move one screen-full down, then go to next unread Space
Scroll up in message body (even if focus on message list) Alt + ↑
Scroll down in message body (even if focus on message list) Alt + ↓
Set focus to message list F8
Set focus to message F9

ThreadsExpand all threads Shift + →
Collapse all threads Shift + ←
Mark thread as read M
Mark thread as read, go to next unread N

E-mail keys: managing
MarkingMark selected message as read K
Mark selected message as read, and go to next unread e-mail G
Mark selected message as read, and go to previous unread e-mail T
Mark selected message as unread Shift + K
Mark all messages in active view as read Ctrl + Shift + A
Move selected message to Trash Delete
Delete selected message permanently, without moving to Trash Shift + Delete

RespondingReply to message R
Reply to all recipients of message, including sender Shift + R
Forward message F
Redirect message D
Continue editing message (Drafts, Outbox, and Sent views) Enter
Focus "Quick reply" field Q
Shift + F9

HandlingSave sender's address as new contact A
Save attachments Shift + S
Label message (for example important or funny) L, 1-7
View all messages associated with sender E
Copy raw message data to clipboard C

ViewingToggle different layout of message list and message body I

Chat keysDownload and list available rooms on chat server Ctrl + Shift + J
Set focus to chat input field Shift + F9

Help keysOpen Opera's help window F1
Search while viewing help page Ctrl + F

Chrome 常用快捷键

Ctrl+NOpens a new window.
Ctrl+TOpens a new tab.
Ctrl+Shift+NOpens a new window in incognito mode.
Press Ctrl+O, then select file.Opens a file from your computer in Google Chrome.
Press Ctrl and click a link. Or click a link with your middle mouse button (or mousewheel).Opens the link in a new tab in the background .
Press Ctrl+Shift and click a link. Or press Shift and click a link with your middle mouse button (or mousewheel).Opens the link in a new tab and switches to the newly opened tab.
Press Shift and click a link.Opens the link in a new window.
Ctrl+Shift+TReopens the last tab you've closed. Google Chrome remembers the last 10 tabs you've closed.
Drag a link to a tab.Opens the link in the tab.
Drag a link to a blank area on the tab strip.Opens the link in a new tab.
Drag a tab out of the tab strip.Opens the tab in a new window.
Drag a tab out of the tab strip and into an existing window.Opens the tab in the existing window.
Press Esc while dragging a tab.Returns the tab to its orginal position.
Ctrl+1 through Ctrl+8Switches to the tab at the specified position number on the tab strip.
Ctrl+9Switches to the last tab.
Ctrl+Tab or Ctrl+PgDownSwitches to the next tab.
Ctrl+Shift+Tab or Ctrl+PgUpSwitches to the previous tab.
Alt+F4Closes the current window.
Ctrl+W or Ctrl+F4Closes the current tab or pop-up.
Click a tab with your middle mouse button (or mousewheel).Closes the tab you clicked.
Right-click, or click and hold either the Back or Forward arrow in the browser toolbar.Displays your browsing history in the tab.
Press Backspace, or Alt and the left arrow together.Goes to the previous page in your browsing history for the tab.
Press Shift+Backspace, or Alt and the right arrow together.Goes to the next page in your browsing history for the tab.
Press Ctrl and click either the Back arrow, Forward arrow, or Go button in the toolbar. Or click either button with your middle mouse button (or mousewheel).Opens the button destination in a new tab in the background.
Double-click the blank area on the tab strip.Maximizes the window.
Alt+HomeOpens your homepage in your current window.

Google Chrome feature shortcuts

Ctrl+BToggles the bookmarks bar on and off.
Ctrl+Shift+BOpens the Bookmark manager.
Ctrl+HOpens the History page.
Ctrl+JOpens the Downloads page.
Shift+EscOpens the Task Manager.
Shift+Alt+TSets the focus on the browser toolbar. Use right and left arrows on the keyboard to navigate to different buttons on the toolbar.
Ctrl+Shift+JOpens Developer Tools.
Ctrl+Shift+DeleteOpens the Clear Browsing Data dialog.
F1Opens the Help Center in a new tab (our favorite).

Address bar shortcuts

Use the following shortcuts in the address bar:

Type a search term, then press Enter.Performs a search using your default search engine.
Type a search engine keyword, press Space, type a search term, and press Enter.Performs a search using the search engine associated with the keyword.
Begin typing a search engine URL, press Tab when prompted, type a search term, and press Enter.Performs a search using the search engine associated with the URL.
Ctrl+EnterAdds www. and .com to your input in the address bar and open the resulting URL.
Type a URL, then press Alt+Enter.Opens the URL in a new tab.
F6 or Ctrl+L or Alt+DHighlights the URL.
Ctrl+K or Ctrl+EPlaces a '?' in the address bar. Type a search term after the question mark to perform a search using your default search engine.
Press Ctrl and the left arrow together.Moves your cursor to the preceding key term in the address bar
Press Ctrl and the right arrow together.Moves your cursor to the next key term in the address bar
Ctrl+BackspaceDeletes the key term that precedes your cursor in the address bar
Select an entry in the address bar drop-down menu with your keyboard arrows, then press Shift+Delete.Deletes the entry from your browsing history, if possible.
Click an entry in the address bar drop-down menu with your middle mouse button (or mousewheel).Opens the entry in a new tab in the background.
Press Page Up or Page Down when the address bar drop-down menu is visible.Selects the first or last entry in the drop-down menu.

Webpage shortcuts

Ctrl+PPrints your current page.
Ctrl+SSaves your current page.
F5 or Ctrl+RReloads your current page.
EscStops the loading of your current page.
Ctrl+FOpens the find bar.
Ctrl+G or F3Finds the next match for your input in the find bar.
Ctrl+Shift+G, Shift+F3, or Shift+EnterFinds the previous match for your input in the find bar.
Click the middle mouse button (or mousewheel).Activates auto-scrolling. As you move your mouse, the page automatically scrolls according to the direction of the mouse.
Ctrl+F5 or Shift+F5Reloads your current page, ignoring cached content.
Press Alt and click a link.Downloads the target of the link.
Ctrl+UOpens the source of your current page.
Drag a link to bookmarks barBookmarks the link.
Ctrl+DBookmarks your current webpage.
F11Opens your page in full-screen mode. Press F11 again to exit full-screen.
Ctrl and +, or press Ctrl and scroll your mousewheel up.Enlarges everything on the page.
Ctrl and -, or press Ctrl and scroll your mousewheel down.Makes everything on the page smaller.
Ctrl+0Returns everything on the page to normal size.
Space barScrolls down the web page.
HomeGoes to the top of the page.
EndGoes to the bottom of the page.
Press Shift and scroll your mousewheel.Scrolls horizontally on the page.

Text shortcuts

Ctrl+CCopies highlighted content to the clipboard.
Ctrl+V or Shift+InsertPastes content from the clipboard.
Ctrl+Shift+VPaste content from the clipboard without formatting.
Ctrl+X or Shift+DeleteDeletes the highlighted content and copies it to the clipboard.