1
votes

I am learning sharepoint client object model these days regarding SP2013, starting with .NET managed client object model. I have seen many examples using var ctx=new ClientContext("") and other using ClientContext ctx=new ClientContext("") for creating clientcontext object. What is the preferred way to use? And alsp, do we need to dispose clientcontext object?

1
Refer this link for Dispose of objects using Client Object Model - sharepoint.stackexchange.com/questions/62901/… - Rohit Waghela

1 Answers

2
votes

The name of this feature is implicitly typed local variable, there is no difference:

Local variables can be declared without giving an explicit type. The var keyword instructs the compiler to infer the type of the variable from the expression on the right side of the initialization statement.

Source: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/implicitly-typed-local-variables

The disposal of ClientContext can be done automatically by Garbage Collector, don't worry:
More Info:https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals