C# 7.0 Features

C# language some Keys to know:

1. In C# language to know the which dot net version you are using at run time you can use “Enviourment.Version”.
You can also find;
Console.WriteLine(Environment.Version);
Console.WriteLine(Environment.OSVersion);
Console.WriteLine(Environment.ProcessorCount);
Console.WriteLine(Environment.MachineName);

2. C# 7.0 Features :-
— 1. Touples:-
— 2. Tuple Deconstruction :- Any object can be deconstructed by defining a Deconstruct method in the class:
for example :-
class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }

public void Deconstruct(out string firstName, out string lastName)
{
firstName = FirstName;
lastName = LastName;
}
}

var person = new Person { FirstName = “John”, LastName = “Smith” };
var (localFirstName, localLastName) = person;

In this case, the (localFirstName, localLastName) = person syntax is invoking Deconstruct on the person.

— An alternative approach for the Person class is to define the Name itself as a Tuple. Consider the following:

Example:- class Person
{
public (string First, string Last) Name { get; }

public Person((string FirstName, string LastName) name)
{
Name = name;
}
}

Then you can instantiate a person like so (where we can take a tuple as an argument):

var person = new Person((“Jane”, “Smith”));

var firstName = person.Name.First; // “Jane”
var lastName = person.Name.Last; // “Smith”

— Touple Intialization :-

You can also arbitrarily create tuples in code:

var name = (“John”, “Smith”);
Console.WriteLine(name.Item1);
// Outputs John

Console.WriteLine(name.Item2);
// Outputs Smith

When creating a tuple, you can assign ad-hoc item names to the members of the tuple:

var name = (first: “John”, middle: “Q”, last: “Smith”);
Console.WriteLine(name.first);
// Outputs John

 

— 3. Out var declaration

The out var declaration is a simple feature to improve readability. It allows a variable to be declared at the same time that is it passed as an out parameter.

A variable declared this way is scoped to the remainder of the body at the point in which it is declared.

In C# 7.0, you can inline the declaration of the variable passed to the out parameter, eliminating the need for a separate variable declaration:-

Example :-

if (int.TryParse(input, out var value))
{
Foo(value); // ok
}
else
{
Foo(value); // value is zero
}

Foo(value); // still ok, the value in scope within the remainder of the body

If some of the parameters that a function returns in out is not needed you can use the discard operator _.

p.GetCoordinates(out var x, out _); // I only care about x

An out var declaration can be used with any existing function which already has out parameters. The function declaration syntax remains the same, and no additional requirements are needed to make the function compatible with an out var declaration. This feature is simply syntactic sugar.

Another feature of out var declaration is that it can be used with anonymous types.
7.0
Example:-
var a = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
var groupedByMod2 = a.Select(x => new
{
Source = x,
Mod2 = x % 2
})
.GroupBy(x => x.Mod2)
.ToDictionary(g => g.Key, g => g.ToArray());
if (groupedByMod2.TryGetValue(1, out var oddElements))
{
Console.WriteLine(oddElements.Length);
}

In this code we create a Dictionary with int key and array of anonymous type value. In the previous version of C# it was impossible to use TryGetValue method here since it required you to declare the out variable (which is of anonymous type!). However, with out var we do not need to explicitly specify the type of the out variable.

 

Find live frequency of Character in string using Java Script.

In this blog i am going to show you a simple program where you find frequency of character in a string using JavaScript.

Note:- Before starts this simple demo i believe that you must have basic knowledge on JavaScript.

Let start;

To do this demo first we need to design a simple web page where we have one textbox where we need to enter some text and we find the frequency accordingly.

In this example bellow all the functionality are defined inside JavaScript function called as “GetFrequency()

 

<html>
<head>
<meta name=”viewport” content=”width=device-width” />
<title>TestKey</title>
</head>
<body>

<h2>Get Frequency of Character from a string</h2>

Enter Your Text :

 </body>

</html>

<scripts>

var charkey = “”;
function GetTheKey(e) {
charkey = document.getElementById(“txtData”).value.substring(document.getElementById(“txtData”).value.length – 1);
}
function GetFrequency(e) {
debugger
var count = 1;
var value = document.getElementById(“txtData”).value;
if (e.which <= 90 && e.which >= 48) {
var checkCount = 0;
var keyChar = e.key;
if (value.length > 1) {
for (var i = 0; i < value.length – 1; i++) {
if (keyChar == value[i]) {
count++;
}
else
continue;
}

if (count > 1) {
for (var i = 1; i < count; i++) {
if (i != count) {
if (document.getElementById(keyChar + i) != null) {
var eleData = document.getElementById(keyChar + i).innerHTML.replace(/.$/, count);
document.getElementById(keyChar + i).innerHTML = eleData;
checkCount++;
}
}
}
}
if (checkCount == 0) {

var lable = document.createElement(“lable”);
lable.textContent = “The frequency of character ” + keyChar + ” is ” + count;
lable.id = keyChar + count;
document.getElementById(“result”).appendChild(lable);
var br = document.createElement(“br”);
document.getElementById(“result”).appendChild(br);
}
checkCount = 0;
count = 1;
}
else {
var lable = document.createElement(“lable”);
lable.textContent = “The frequency of character ” + keyChar + ” is ” + 1;
lable.id = keyChar + count;
document.getElementById(“result”).appendChild(lable);
var br = document.createElement(“br”);
document.getElementById(“result”).appendChild(br);
count = 1;
}
}
else if (e.which == 8) {
// if (document.getElementById(“txtData”).selectionStart != 0) {

if (document.getElementById(“result”).lastChild != null) {
var ele = document.getElementById(“result”).lastChild;
document.getElementById(“result”).lastChild.remove();
if (document.getElementById(“result”).lastChild != null) {
var iNum = document.getElementById(charkey + count).innerHTML.substring(document.getElementById(charkey + count).innerHTML.length – 1);
if (parseInt(iNum) > 1) {
var eledata = document.getElementById(charkey + count).innerHTML.replace(/.$/, iNum – 1);
document.getElementById(charkey + count).innerHTML = eledata;
document.getElementById(“result”).appendChild(ele);
}
else {
document.getElementById(“result”).lastChild.remove();
}
}
}
}
//}

}

</scripts>

Note:- Do copy and paste above code and remove the last character ‘s’ from script tag.

Any thing not work for you feel free to drop a comment in the comment box; always happy to listen your feedback.

Happy Coading 🙂

#Share2Know @SURYAN_Mode

 

IT Industry Journey.

A Few word about my IT Experience and some career advice what I learned.

IT Journey!!!

Greeting all of You !!!

I have completed 4.7 year in IT industry, apart from that working on many Dot Net Developer Community since last 4 years with providing on-line training many Dot Net Developer Pro on various Dot Net Technology.
Yes it’s true that; It’s an beginning of my IT career more year to go now.
So friends I am not an Tech Guru or Tech Expert to advice you; but yes i can tell you
what i learn in my career in this small amount of time.

I started my career as a .Net Developer in a company called as Focussoftnet and I worked there for 4.7 year. I resigned that company recently and going to start my IT Journey in another MNC company.

I learned many things in this company; special thanks to my Project Manager and our VP for their advice and support; always heartily thanks to Azizur Reheman (PM) for all time support and giving best suggestion and showing a right path, also giving me always R&D type of Task.
I really thankful sir for your faith and believe over me and giving such type of challenging work; as a fresher you know well it’s difficult for me to complete it; but i really happy that you giving me that task as an opportunity to use all my knowledge and ideas, yes it took time to complete but due to your support and giving me time i made all this possible.

These are few bellow points what i learned in this year of experience;

If You are a Fresher Joining to any Company What You do :-

1. As you are fresher it means you required to work on any technology what company gives you.

Tips To Remember:- Here keep in mind always that if you are although a fresher and you did specialized in any technology which company required today; for eg:.Net,Java,PHP and etc then you can apply for that company where you matched your technology; so that you are 90% sure that you are going to work on that technology what you already have specialized. May be you are thinking why 90% not 100% Right ???
Yes Not 100% because you are fresher; so keep in mind if company don’t have any project currently on that particular technology then you required to work on what you get. So set up your mind like that and be flexible.

Their is a way to avoid this 10% too. The idea is before apply the Job first check the Job description clearly what they mentioned and if you all round then in HR round Just clarify once again what technology i am going to work and tell what specialized you have; so many case you get the same technology what you have specialized. So don’t bother about this 10%; just focus on your technology.

2. Once you joined in a company as fresher then don’t think that you can get work on project immediately. Actually it’s differ company to company. Yes you got work immediately if company has running project.
In my career i see many of us frustrated
that i am not getting work; just i am going to office and coming back; also not getting the work what i needed.
May be many of us face same problem; i have also face the same; but i utilize my time on different way without frustrated. The best thing i need to say what i followed; if company won’t giving you work immediately then start learning by your own. Start to practice the concepts. Their are lots of project at Github you can just download it and start doing by your self; otherwise start Google on a particular topic then you get lots of resource on that to read.
If you think you already have all the knowledge with you and you required work to do then the best thing i can suggest that their are lots of open source project available at Github; you just need to login and start contributing your ideas inside that project. Now you might think that what is my benefit??
Right ??
Yes; First of all you get some new ideas and knowledge as well as more importantly people in community going to recognize you if you are a good contributor .In IT industry you required a good connection over all type of people around the globe. As a fresher if you started contributing your ideas inside the project then in very few time you might well recognized inside the community which helps you a lot in your IT Journey.
If you start your career as a Software Developer then you should required to have the art of Self Learning; this only helps you in life long.

Note :- If you need more details about this how can you contribute? for all type of query i am always available and happy to help you. You find all details of me here..

3. Do your task first what given to you; if you finish the task before the time then just inform to your reporting manger; Yes you need to inform not sit ideal why so ???
Because you are joined as a fresher keep in mind to build up your image and make recognize between many employee you should tell so that you create a positive view in front of your Reporting manger.

Now you might think what was it’s advantage ?
You got confirmation very quickly and the hike also good :). Here i am not saying it this happen to all company but yes it true many company treats you as good employee.

4. Don’t be show more your talent.
Yes you should say what you have asked; not say more then that.If you understand the environment and you think your view is required then tell.
Key Point :- Build up Your image through your work not by saying in word.
You only know to whom over you can show your talent show your talent when required and get value of this.

5.Build a good relationship To Everyone :-
As you joined as fresher keep respect to everyone and make yourself more flexible. If any body wants your help share your ideas.
Key Point :- Always make your self update and share the new thing with other and make a good connection among all.

6. Don’t go on your believe always goes on what is the realty.
If you goes on your believe and think yourself it may be like that;
for eg: A task given to you and the task is not clear to you while it is giving; so don’t imagine your self that the task would be like that; do not do this just go and ask once again who ever giving you.
Key Point :- Do not be heighted to ask; if you get fear to ask then you can not rectify the mistake and waste you time. So ask as many time you won’t understand the task. If you ask then only it crate a confidence with in you and the team lead who is giving you task he get positive attitude to-wards you.

Lastly thanks to All My Team Member whom with I worked on.

I really miss the work environment and all of You Guys !!

Hope to See you soon Guys !!

Hope You like this article and it helps you on your way in IT Life.

Share your valuable comments.

 

Suryakanta Nayak,  Software Engineer
SuryakantaN@Solutionsoftware.com
 – Health Plan Partner of the Year

#Share@Know

 

 

Few line for Developer’s; Must Read !!!

We are the developer who working today with different technology. Every day handling different situation; and also getting different problem where we might think that we are getting stuck after doing many search over internet; now it’s time to take help for some one else.
Is not it ??
Yes; so what we do is ask some one other developer or any of our friends Right ?
Yes;
But, still we are not finding any solution then ???
If you ask me then I have answer.
My answer is visiting any technical Forum and asks the same question there.
Who are new to .Net technology might be do not know about what is forum ??

and how it is working ?
Let me tell you;

Today we have lots of technical forum to ask the question; if you are working on .Net technology then we have specific forum for each technology. Today’s many developer are actively answering the question and what I saw one of the best technical forum for web development is Asp.net forum.
Apart from that another best one for any Microsoft technology related query is MSDN.Com.
You can ask any question/doubts there.
Don’t think that you can get answer immediately ; yes you can get the answer immediately if and only if you ask the question in appropriate manner.

So what I mean by appropriate manner?

    • Your question not so much lengthy explanation with unnecessary things; so make as much as smaller and keep it as simple.
    • Post your code if you think explanation required code stuff to understand.
    • Always choose the appropriate categories while posting the question that is most important.

So don’t be hesitated to asking your question; it’s not like that you can get your response quickly; but remember you definitely get the answer as depends upon how you explain the question. What I saw in my case maximum within four to five hour I get the response. So keep penance!!!
I am not saying that you can improve your way of asking question in one day but if you do it regularly then definitely I say you can improve a lot and you get quick response from other developers.
If you are asking question in Asp.net forum and MSDN forum then I definitely sure that you can get response to your question; in rare case you can not get; but most probably all the question get solved very quickly.

How it’s working ?
Many of us actually don’t know how the forum works; it’s not like that you are only asking question and getting response; behind the seance there are lots of stuff happen;
Basically if you are asking question in any Microsoft forum then Microsoft has it’s own moderator (moderator are the developer who have lots of experience and actively working with community and also their are various Microsoft Most Valuable Professional  (MVP))who are going to check your question whether your question related to Microsoft technology or not and also they check on which categories you are asking question. If they found any point of time your question is invalid then they can immediately remove it from forum and they send you a private message about this.
So keep in Mind this while posting question!!!
Many developer today actively contributing their valuable response in MSDN forum.
Which makes you guarantee that you get your response quickly.

If you see that many days happen you are not getting any response of your question or valid answer of your question then the best way is just open another thread and ask same question in different manner.

Last one for all; Use forum also answer the question as well; not only ask the question. So do regular visit to forum and try to read the question as you can; and on the way of reading one by one question when you feel that you can answer it just answer it by click on reply.
If you do so you are now actively work with community on a bidirectional manner.

Last but Not the List:-
We all asking the question but it’s important to keep in mind that once your question get resolved make the question mark as answer so it’s helps the community to recognize that what are the question resolved till the date. A part from that if you mark as answer then it means that you are actively engaged with that thread.

If you are belong to .Net Techies then;
Some of the best forum where you get directly in by just simple sign in:-
1) All in One as I told above i.e. is MSDN Forum
2) If specific to web technology then Asp.net Forum
3) C# Corner Forum
4) CodeProject Forum

So what we see form above that we are not alone today we have whole community with us.
If we are working on .Net technology then we have many more developer from across the country whom we can get collaborate by asking the question and get the response.
Keep asking and visiting forum.
That’s all;
Hope above information help you.
You can find my thread on MSDN forum Here

Please give me your valuable feedback and tell me if any thing i left here.

Thanks.

Happy Coading. 🙂

Patterns in Java Script

Introduction :-

In Java script we have different  types of pattern to write our code.  We all web developer write many java script code every day and we do not know how much clean and safety our code. So today in this article I am going to tell you about basic JS Patterns which helps to write an effective java script code; and we also going to see many OOPs concept while we go through the different patterns.

Background :-

Let’s starts a deep drive in to Java script patterns;

We have three types of pattern in JavaScript these are :-

  1. Function as Abstraction Pattern.(Abstraction in Java script)
  2. Function to Build Module Pattern. (Encapsulation in Java script)
  3. Function to avoid Global variable Pattern. (Anonymous function in Java script)

Let’s see one by one with live examples;

  1. Function as Abstraction Pattern:-

If you are coming from C# language or any object oriented programming language background then we probably all know about abstraction.

Let me once again quick remind!!!

Abstraction :-  Hidings the details and providing only what is necessary.

To understand above let’s jumps to our demo;

Note :- Here I am not going to create any project in visual studio. You can use any editor to write this simple java script function or else you directly open you browser window and open the console window in browser by pressing F12 then press CTL+L in Chrome and CTL+Shift+L in Firefox to clear the console window and pest these bellow code.

Abstraction Partern Demo :-



//Function as abstraction

var Do=function(){

console.log("Do is Called !!!");

}

var DoSomething=function(f){

console.log("Before Do function executed !!!");

try{

f();

}

catch(ex){

console.log(ex)

}

console.log("After Do function executed !!!");

}

DoSomething (Do);

//End of Abstraction


Explanation :- In the above program we have declare two variable called as Do and DoSomething .Using this two variable I declare two functions.

So, What I am doing here is hiding the details of Do Function inside DoSomething Function. While calling I am only call DoSomething function which automatically get executed Do function.

Now what is it’s advantage ?

Advantage of this pattern is if you want to execute some block of code before and after the specific JavaScript function executed then it’s much helpful.

  1. Function to Build Module Pattern:-

In this pattern we are going to understand how we do encapsulation in JavaScript while write function in JavaScript.

Note :- It’s very useful pattern while doing JavaScript program, I recommended use this pattern while writing JavaScript code.

Let’s Jump in to Demo;

//Function to Build Module
var Do= function() {  //This is Global variable

var Job1 = function() {  //This is Local varibale.

console.log("Job1 is Called !!");

};

var Job2= function() {

console.log("Job2 is called !!");

};

return {

process1:Job1,

process2: Job2

};

};

var objDo= new Do();

objDo.process1();

objDo.process2();

//End Build Module

Explanation :-

In the above program I have declare a function using Do variable. Inside this function I have again declare another two function using local variable called as Job1 and Job2. Here I declare two function you can declare as many number as your requirement.

Hence this Job1 and Job2 are local under this Do function; so we cannot access this function outside of  Do function. Job1 and Job2 are only accessible inside the Do function only. Here Do is encapsulated both Job1 and Job2 function.

Remind Oops what saying about encapsulation ??

Hence here we achieve encapsulation as well.

Well; here it’s important to understand that how I am calling Job1 and Job2.

See above what I am doing is that I am returning job1 and Job2 function from Do function.

Always remember every function in Javascript always return some value by default.

To call the function we need to create an object of Do function and using this object I can call all the function define under Do.

Let’s discuss what is the advantages of this pattern?

  • Providing security over our code.
  • More clean code.
  • Avoid duplicate code and write the code specific to our page/view.

Based on my experience:-

Last point which I say above is “Avoid duplicate code and write the code specific to our page”; this is really useful if you are working as a web developer then you might understand this point very clearly.

In my working life what I see is that many programmer write the function but while giving name we are not sure that whether the name is used by someone else or not ??So while calling it’s get confuse that why our function not get executed rather executing someone else function; that due to same name of function.

So if we follow this above pattern we never ever face this problem.

 Hence I always recommended to all of you please follow this pattern.

  1. Function to avoid Global variable.

In this pattern we are going to see how to write a Global function also we see Immediately Invoked Function (IIF).

Let’s see this in demo;


var DoMain = function() {  //This is Global variable.

var Do= function() {

var Job1= function() {  //This is Local varibale.

console.log("Job1 is Called");

};

var Job2= function() {

console.log("Job2 is called");

};

return {

Process1:Job1,

Process2: Job2

};

};

var objDo= new Do();

objDo.Process1 ();

objDo.Process2 ();

}

DoMain();

Explanation :-

If we analysis from first pattern program to this program then what I did in this is I write all the code inside one global variable called as DOMain and making it as a function.

So it’s easy to understand that I am just calling the DoMain() function and we get the same output as previous program.

So what you think nothing is new here right??

Yes….no…  🙂

Let see the new thing bellow :-

//Anonymous function or IIF function

(function(){

var DoMain= function() {  //This is Global variable.

var Do= function() {

var Job1= function() {  //This is Local varibale.

console.log("Job1 is Called");

};

var Job2= function() {

console.log("Job2 is called");

};

return {

Process1:Job1,

Process2: Job2

};

};

var objDo= new Do();

objDo.Process1 ();

objDo.Process2 ();

}

DoMain();

}()); 

Explanation :-

If we analysis above example then we see that there is no variable I deified to store the function; rather I define a self-function which is similar to the anonymous function in C# language.

This type of Function basically called as Immediately invoked function (IIF) in Java script.

So while we writing this type of function then that function get executed immediately after DOM element loaded.

Note :- Basically this type of pattern used in case of developing plug in. We also see many plugin has this type pattern, if you see jquery.flowchart.Js plugin then you can get a clear picture that whole plugin developed using this pattern only.

Conclusion:-

So this all about our java script patterns and their purpose of uses.

Hope this is help full to you understanding all these patterns with simple example.

Above explanation based on my own experience and learning; so if you found anything mistake in that or any example not work then feel free to give you feedback.

Please say about what you feel about this article; which helps me to improve myself.

Thanks all.

Happy Coading.

🙂