Posts

Showing posts from 2018

Dependency Injection in C#

             Dependency Injection is a Software Design Pattern for make Loosely coupled code.There are 3 main ways to implement dependency injection.They are Constructor Injection Property Injection Method Injection 1.Constructor Injection                             It uses only one Parameterized constructor. (e.g) 1. using System; interface ICar { void ShowColor(); } class Maruthi:ICar { public void ShowColor() { Console.WriteLine("Maruthi Car"); } } class ConstructorInjection {    private Maruthi _maruthi; public ConstructorInjection(Maruthi m) { _maruthi=m; } public void ShowColor() { _maruthi.ShowColor(); } } public class Program { public static void Main() { ConstructorInjection cn = new ConstructorInjection(new Maruthi()); cn.ShowColor(); } } 2. public...

Interfaces in C#

Interfaces can have set of properties,methods,events and indexers but has no implementations. The implementation of each member of the interfaces will be created in the child classes.So we may see all these vividly below. An interface defines the signature of properties,methods,events and indexers but not an implementations. Interface members are public by default .So don't need to specify access specifiers. Access modifiers of the Interface can't be changed.Because it is Internal by default . The class must be implemented all the properties,methods,events and indexers of the interface if  the class inherits the interface. The implementation of the properties,methods,events and indexers in the class must have the access specifier public . Object can't be created for an Interface. (e.g) using System; public class Program { public static void Main() { Child child = new Child(); child.Show(); child.ShowAge(); child.ShowN...

Inheritance example program

Program using System; public class Program { public static void Main() { DisplayYear s = new DisplayYear(); s.DisplayName(); s.WishMe(); s.ShowYear(); } } class Newyear { public  virtual void DisplayName() { Console.WriteLine("Wish"); } } class Wish:Newyear { public  override void DisplayName() { base.DisplayName(); Console.WriteLine("You"); } public void WishMe() { Console.WriteLine("Happy New year"); } } class DisplayYear:Wish { public void ShowYear() { Console.WriteLine("2019"); } } Output Wish You Happy New year 2019

Know vocabularies-I

Present                  Past            Past participle Send                      sent            sent Smite                    smote        smitten Strike                    struck        struck Undergo               underwent undergone Wear                      wore         ...

ViewData,ViewBag,TempData and Session in Dotnet Core

           Today we are gonna learn about data transfer mediums in dot net core.I believe it will be helpful to make a flexible web applications.Here we go, ViewData           *It is the object of dictionary.It is derieved from ViewDataDictionary class.               public ViewDataDictionary ViewData{get;set;}         *It is used to pass data from controller to corresponding view.         *Its lifespan lies only during the current request.         *Its value will be null if redirection occurs.         *Typcasting is required to get data and null value checking has to be done to avoid error. ViewBag            *It is a property of ControllerBase class.             public object ViewBag{get;}          *It is used to pa...

Authentication in Asp.net

Authentication is the process of obtaining some sort of credentials from the users and validates the users identity based on the credentials.There are 3 main authentication types.They are 1.Windows authentication 2.Forms authentication 3.Token-based authentication 1.Windows authentication This uses local windows users and groups to authenticate.This  supports only windows operating system.So it  is suitable for Intranet networks where the servers ,clients and users all belong to the same windows domain.It's further classified in to 3 types a)Basic authentication           Username and password is sent as Base64-encoded strings.It is very week form of authentication. b) Digest authentication          It over comes the issues of basic authentication by using MD5 Hashed.This is very hard to decipher. c) Integrated authentication     Kerberos authentication or NT ...

Dynamic table binding using jQuery ajax call

Today we are gonna learn about dynamic table binding using jQuery.This is very useful in most cases.We need to create a new HTML table and bind using jQuery. So let's start here. jQuery $(document).ready(function () { var tr=''; $.ajax({ type: "post", url: "Provide your ajax function url here", dataType: "json", success: function (data) { if (data.length!= 0) { $.each(data, function (key, data) { tr+= "<tr><td>" + data.id+ "' </td></tr>"; }); } $('#test tbody').empty().append(tr); }, error: function (error) { alert(error); } }); }); HTML <table id="test"> <thead></thead> <tbody></tbody> </table>

Skills for a Software Developer

1) OOPS 2) Any one scripting language 3) Any one programming language in depth 4) Software Architecture and design paterns 5) Deployment and release techniques 6) Code Management 7) Software process and documents 8) Seperation of Concerns Concepts 9) Single responsilbility Concepts 10) Art of Google Surfing

Find the number of occurrences of a specific character in a string using C#

using System; namespace saran { public class Program { public static void Main() { Console.WriteLine("Enter the string..."); string name =string.Empty; name =Console.ReadLine(); string c =string.Empty; Console.WriteLine("Enter the character..."); c =Console.ReadLine(); int cnt =(name.Length)-name.Replace(c,string.Empty).Length; Console.WriteLine(cnt); } } }

Find Whether the given string is palindrome or not using C#

If the given string and the reversed of the string is same then it is called "Palindrome".For instance Madam-madaM mom -mom Example using System; namespace saran { public class Program { public static void Main() { Console.WriteLine("Enter the string"); string name =string.Empty; string reversename =string.Empty; name = Console.ReadLine(); char[] n = name.ToCharArray(); Array.Reverse(n); reversename=new string(n); if(name.Equals(reversename,StringComparison.OrdinalIgnoreCase))    { Console.WriteLine(name+" is polindrome");    }    else    {   Console.WriteLine(name+" is not a polindrome");    } } } } output Enter the string mam mam is polindrome

Collections in C#

Collections are the type of classes which store series of information.There are 2 types of collections in c#.They are Generic collection Non-generic collection 1.Generic collection                                             Generic collections are depended in specific data types such as int,string and so on.Generic collections come under " System.Collections.Generic;   " library. i)List                          List requires only one type argument(in any data type).                        Example  using System; using System.Collections.Generic; namespace saran { public class Program { public static void Main() { List<int> age = new List<int>(); age.Add(25); age.Add(24); age.Add(23); foreach(int ...

Sealed Class in C#

Sealed class is used stop the inherit feature of the class. In other words non inheritable classes can be created using sealed keyword. Generally we can inherit the class and use the properties . In case if we don't want to inherit the class we have to add the keyword "Sealed".If the class has the keyword "Sealed" then it can't be inherited. Example:1 using System; namespace saran { public class Program { public static void Main() { Test t  =new Test(); Console.WriteLine(t.name); } } sealed class Test { public string name="ssn"; } } Output ssn Example:2 using System; namespace saran { public class Program { public static void Main() { Test t  =new Test(); Console.WriteLine(t.name); } } sealed class Test { public string name="ssn"; } public class derieve:Test { } } output Compilation error (line 19, col 15): 'saran.derieve': cannot derive...

Constructors in C#

                         Constructors are the special type of methods which are invoked automatically when the object of the class is created.Constructors are used to initialize the data members of the class.If no constructor is created then compiler will create default constructor .The default constructor initializes numeric fields 0 and string fields null . A Class can have any number of  constructors Constructors don't have any return type. Within a class only one static constructor can be created. Static constructor can't be a parametrized constructor. only one static constructor can be created in a class. There are 5 types of constructors in c# namely, Default constructor Parametrized construtor Copy Constructor Static Constructor Private Constructor 1.Default Constructor                                   ...

Finding the Primary and foreign keys of the table in Sql

Image
We have some ways to find the primary and foreign key information in Sql. Some of those are, 1.sp_help table name                           This will provide all the information about the specific table such as column names,constraints and so on. (e.g) sp_help eistmuser output 2.sp_pkeys  table name                                   This will return only the primary key details of the specific table. (e.g) sp_pkeys eistmuser output  3.sp_fkeys  table name                                                                                 This will return only the foreign key deta...

Good Thoughts and deeds.

Respect is earned by giving respect You will get what you  deserve,   not what you desire. Appreciating efforts of your parents. Preserving your hobbies. Throwing empty cans/ chips packets in dustbins instead of throwing them elsewhere. Exercising for 10 mins regularly. Having a positive mindset towards everything. Never expect anything from anyone as it always ends in disappointment. Never admit your parents to old age home. Living in the present

Access Modifiers in C#

                                 Access modifiers are the keywords which describe the accessibility of the class or its member.we can control the scope of the class and data types by this access modifiers. We can achieve Encapsulation using Access modifiers. There are 5 types of access modifiers in C# namely, Public Private Protected Internal Protected Internal 1.Public                Public is the most common access modifier.There is no restriction for public access modifier. It can be accessed from anywhere. It can be accessed by objects of the class. It can be accessed by derived classes. (e.g) using System; namespace saran { public class Program { public static void Main() { test t = new test(); t.name ="ssn";        Console.WriteLine(t.name); } } class test { public string name{get;set;} }...

Classes in C#

                Class is a collection of  related variables and methods . It represents the state and behavior of an object. A class definition can contain                 1.Fields                 2.Properties(accessors,mutators)                 3.Methods                 4.Constructor Properties are special public methods that allow a user of the class to " get " a variables value, or to a " set " a value (e.g) using System; public class Program { public static void Main() { EmployeeDetails employeeDetails = new EmployeeDetails(); employeeDetails.EmpAge=25; employeeDetails.EmpName="ssn"; employeeDetails.ShowDetails(); } } class EmployeeDetails { //Fields private string empName; private int empAge; //Properties public string EmpName ...