1,524 total views, no views today
1,524 total views, no views today
In Build 2015, Scott Hanselman announced one really cool tool Visual Studio Code. I thoroughly enjoyed his presentation. So, as soon as he done with the presentation, i just downloaded the same from http://bit.ly/visual-studio-code and started testing the same. Best thing is that it installed in a minute literally in a minute. So, 1st reaction is fast and amazingly fast. For people like me who love coding and can’t manage to have full suite VS installed on all the machines, Visual Studio Code is a boon for them.
It gives me all the required intellisense what is offered in VS, plus this is platform independent. So, doesn’t matter whether i am running on Windows, MAC or LINUX. I can open the file in Code, get the real time feel of VS; do the changes and bang. Let’s jump to quick demo.
Below is the snippet of my movie review app where in i have added my API with ease from VS Code.
Here, you can see we also get same intellisense support as we get from VS.
Also, if you want to quickly jump between the files and do some changes, you can do the same with CTRL+O option as shown below.
While writing test case also. we get the similar intellisense support. Also, we can go ahead and debug our app and we get call stack, watch and variables as well. For debugging little environment settings needs to be done in project.json file. This is well drafted in VS Code documentation. Thanks for Joining me.
2,258 total views, no views today
In this section, we’ll see when to choose which binding. Below I have pasted one simple self-descriptive decision tree.
Let me explain the same. So, before choosing any binding 1st question we’ll ask is are we inside a firewall? Then if answer is no and we are using .Net to .Net communication then in that case, we can go for WsHttpBinding as it supports complete WS-* stack and much more feature rich than the basic one. Now, if Client is not .Net to .Net, then do you need to support older version of java clients or .Net 2.0 or below, then you can use BasicHttpBinding. Here, you won’t get any out of the box features provided by WS-* stack but at least you can communicate.
However, if you are inside the firewall and client is not .Net to .Net, then you can ask Supporting Older Version question. And if it’s a .Net client and inside the Firewall, then next question would be if it sits in the same machine or in other words its local In-Process only then you can use NetNamedPipeBinding. And if the client is not on the same machine and it’s more conventional like server on one machine and client on other, then next question I would ask is whether you need Disconnect? If the answer is yes, then you should use NetMSMQBinding. If the answer is no, then next question I would ask is whether you need reliability? Now, if you don’t require reliability you can use NetUDPBinding otherwise NetTcpBinding. So, this is the most common use case of before choosing any binding.
Thanks for joining me.
2,366 total views, no views today
In today’s discussion we will see hashset in action. This is again one of the types of C# collection and very efficient. HashSet
Let’s consider, you have few elements in the collection and then you again added few more, then in that case there is no guarantee that it will prevent duplicate items to get added in the collection. In order to prevent it, we use hashset. HashSet guarantees that it won’t add any duplicate value to the collection.
and it will produce me the below output.
However, you can restrict the same before adding by putting extra line of code as shown below.
But, this is quite inefficient way as it will downgrade the performance if the list is big; As contains method examine the entire list till it matches the requirement. One way to fix this problem is by using hashset as shown below in the example.
Now, let’s consider one scenario where in mismatch in case and then you are trying to add the same.
then, it will fail and add the same in collection like
we have seen this problem earlier while dealing with dictionary. Now, quick fix around the same is using custom comparer as shown below.
now, lets consider a scenario where in you have two collections and you need to find the common value. In case of set it is called intersection of sets. Below in the example I have two sets having some common values.
This will print the below result.
Now, let’s see an union operation on the same. Union means either in A or in B.
This will print the below result.
Let’s look another scenario where in you want those values which are unique in both the lists.
This will give me below result.
Another scenario is subtraction of sets. Means find value that are only in 1st collection.
It gives me below output.
HashSet out of the box also gives flexibility to compare two sets, means check whether they are equal are not. It literally means whether values in two sets are equal or not as shown below.
i hope you have liked this piece. Thanks for joining me.
2,180 total views, 2 views today
In Today’s example we will see some basics. Here, in the below example a sample implementation of multiple interface getting implemented explicitly in a class.
1,519 total views, no views today
In today’s session, i will just share one of the debugging tips where in you have limited access to the box. Recently, for one requirement i promoted my code and that gets promoted to production and then tester approached me and said your change is not working. I said not possible, as i can prove the point with the same code running in my local box. But, error was there and it was not working in prod. So, what i did is requested for the DLL deployed in prod environment. And i tried below steps to reproduce the same locally.
1) 1st i replaced the same dll in my local box with the prod version and then it banged and gave me proper CLR Exception as shown below, at this point i proved that code is not deployed.
2) 2nd, I went one step ahead and compared my local box DLL with prod box. This also proves the point.
so, the idea is stay confident and prove confidently. Thats it.
1,727 total views, no views today
In this section, we’ll see how to effectively use .Net Types in order to increase the application performance. As we all know that .Net Type system offers 2 kinds of type, 1) Reference Type and 2) Value Types. Reference types are nothing but i can say any class you are writing is a reference type getting allocated on the Heap. so, basically on reference types we can apply OOP methodology, locking and bunch of other methods.
However, in Value types you can’t get these flexibilities. Also, value types are getting allocated on stack avoiding pressure on Garbage collector. you should choose value types wisely means only choose value types when your application is performance critical otherwise Value types may include variety of complexities later in the program. consider a simple example shown below.
below program is fairly simple, 1st i allocated 10 million instances of int on the stack and then tried to reach out the last element in the list. I also repeated the same step 25 times and then at that time i captured the GC instances and time elapsed. Normally, we write simple program this way
Now, when i run the same, it will produce me the below result as shown below in the screen shot.
Now, in the 2nd version, what i am going to do is override the equals operation, so it does suppress the use of reflection at runtime, but still involves one boxing operation for comparison.
now, when i invoke the same like shown below.
then, it will produce me the below result. It does improve the performance.
Now, lets see the another example with IEquatable implementation.
it will produce me the optimized result.
so, contains method check for equality in the list and if we have collection like the above one, then it would be a big performance issue. Now, with IEquatble implementation same job is achieved and achieved faster. This interface has just one method and that is equals method and it takes value type as parameter. so, rather than relying on default implementation of object.valueType, this kind of approach will be really performance booster. Thanks for joining me.
3,133 total views, no views today