.net - Difference between datacontext and normal object creation in C# -


i have seen video @ different windows, presenter follows different styles.

for instance:

in 1 window, uses below:

employeeviewmodel evm = (employeeviewmodel)this.datacontext; evm.display(); 

in another, uses like:

employeeviewmodel evm = new employeeviewmodel(); evm.display(); 

whats difference technically , best way use ? please me understand difference.

the first code fragment retrieves displayed viewmodel. (it should null-check)

the second code fragment creates new instance of viewmodel.

because not clear display() does, hard explain difference between effect of 2 fragments second fragment (unit)test of viewmodel ignores view.

there no best way far can see because both fragments serve different purpose.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -