Mar 3, 2020

ARRAYLIST IN C# (Diff. b/w Array & ArrayList )

ArrayList in c#

            "ArrayList is a class of Collections^ ,and it's a data structure that store collection of data just like an array". But it's is little bit different than ArrayList See the detail difference between Array and ArrayList at bottom of this page.  

EXAMPLE OF ARRAYLIST

      1.    How to declare ArrayList in C#
To declare an ArrayList first step to add the directive System. Collection, and what have to do is we have to the instantiate the instance of ArrayList as we did  to the class instance with the help of new keyword see the example
        using System.Collections;
        static void Main()
        {
            ArrayList List = new ArrayList ();
            // the name of ArrayList will be 'List' or you can chose your own name
 }
      2.    How to add item/values into an Arraylist in C#
arraylist, array vs arraylist in c#, java arraylist, arraylist in collection
arraylist in c#
            With the a help of Add keyword we will add object type data in ArrayList
See it
       static void Main()
        {
            ArrayList List = new ArrayList ();
            List.Add(100);
            List.Add("Jhony");
            List.Add('a');
        }
      3.    How to read an ArrayList in C#
Like the old process but little bit change we have to use the Add keyword like this
       static void Main()
        {
            ArrayList List = new ArrayList();
            Console.WriteLine("Enter items into ArrayList");
            List.Add(Console.ReadLine());
        }
       4.    How to write and display the output of an ArrayList in C#
            Because of the ArrayList we will use foreach loop to print the ArrayList
       static void Main()
        {
            ArrayList List = new ArrayList();
            Console.WriteLine("Enter items into ArrayList");
            List.Add(Console.ReadLine());
difference between array and arraylist, arraylist, array    
array vs arraylist
            List.Add(100);
            List.Add("Jhony");
            List.Add('a');
            Console.Write("Array items are ");
            foreach (object obj in List)
                Console.Write(" " + obj);
            Console.ReadKey();
        }
      5.    How to insert item/values in the middle of ArrayList
            For this you to specify the index number at the place we want to add the item and by using insert keyword we will insert at any point. Like suppose the above program I want to add 150 in between the "Jhony" and 'a' thus we have to add at index number 3 because index start at zero let do it.
        static void Main()
        {
            ArrayList List = new ArrayList();
            Console.WriteLine("Enter items into ArrayList");
difference between array and list, java list vs arraylist, array and arraylist, arraylist example
array to arraylist
            List.Add(Console.ReadLine());
            List.Add(100);
            List.Add("Jhony");
            List.Add('a');
            List.Insert(3, 150);
            foreach (object obj in List)
                Console.Write(" " + obj);
            Console.ReadKey();
        }
      6.    How to delete item from middle of ArrayList
            By use of either Remove keyword and specify the 'object obj'. Or RemoveAt keyword by specifying index number. Suppose above program I want to delete "Jhony" we have two ways
First (Remove keyword and specify the 'object obj')       
static void Main()
        {
            ArrayList List = new ArrayList();
            Console.WriteLine("Enter items into ArrayList");
arraylist clear, arraylist of objects in java, array vs arraylist c#
array to arraylist
            List.Add(Console.ReadLine());
            List.Add(100);
            List.Add("Jhony");
            List.Add('a');
            List.Insert(3, 150);
            List.Remove("Jhony");
            foreach (object obj in List)
                Console.Write(" " + obj);
            Console.ReadKey();
        }
Second (RemoveAt keyword by specifying index number)
       static void Main()
        {
            ArrayList List = new ArrayList();
            Console.WriteLine("Enter items into ArrayList");
            List.Add(Console.ReadLine());
            List.Add(100);
            List.Add("Jhony");
            List.Add('a');
            List.Insert(3, 150);
            List.RemoveAt(4);
            foreach (object obj in List)
                Console.Write(" " + obj);
            Console.ReadKey();
        }

Mar 2, 2020

COLLECTIONS IN C#

dynamic array, collections in c# with examples, array vs arraylist, collections in c#
collection in c#

COLLECTIONS IN C#

"Collections in c# are a dynamic array means it can store multiples items/values as object type like array."  
Collection contain of many classes like ArrayList, Hashtable, Stack, Queue, Linkedlist, Sortedlist and many more in .net

Why we use Collections instead of Array

            The collection is came into play to eliminate some drawback of an array that's are
1- We cannot increase the size of array ones it formed means if we want to increase the size then we can do it by two methods. Either we make a new array and copy the values form old to new. Or we can do this with the help of Array. Resize keyword but the drawback is it destroy the existing array and create a new array by adding the old values into the new one.
2- The second draw back of an array is we cannot add a value in the middle of an array it's not possible with an array.
3- Thirds drawback is we can't delete a value form the middle of an array
            But with the help of collection we can performed the above three task smoothly because it contain a property call  auto resizing, that's mean whenever we keep adding the value this size of collection increasing automatically by adding one new box to the dynamic array1. Second we can add a new value in the middle of a Collection2  and lastly Collection allow us to delete a value from its middle3.  Follow the link to see detail with example.
            However the Collection contains multiple classes under the namespace System. Collections such as ArrayList, Hashtable, Stack, Queue, Linkedlist, Sortedlist and many more in .net all these classes are defined in the library and we just use it. These collections are Non-Generic Collections
            When we came across using the Collection then the most using collection is the ArrayList

SYNTAX OF COLLECTION (ARRAYLIST)

     ArrayList <name> = new ArrayList ( );
    After then we can add Object values in the ArrayList







collection in c# with examples, arraylist example, dynamic array example
c# collection example 

Example of Arraylist (Collection)

class Program
{
  static void Main(string[] args)
 {
   ArrayList list = new ArrayList();
   Console.Write("Enter items/ values = ");
   list.Add(Console.ReadLine());
   list.Add(100); list.Add(200); list.Add(300);
   foreach (object obj in list)
   Console.WriteLine(obj);
   Console.ReadKey();
 }

}

Feb 28, 2020

How i do freelancing without skill

Freelance Work That Require No Skillful Skill

        Some freelance works that requires no proper experience and not has to learn outside of our daily works just focus on some rear things and you can easily do freelancing..From my respected sir 'Sir Hisham Sawar' some very important tips and works that will bring a positive changes in you career specaially for medical, law and engineering student that want to do freelancing. 
  
            

how i do freelance without skill, works that requires no skill in freelancing
freelancing without skill



THREAD PRIORITY IN MULTITHREADING


thread priority, thread priority in java, default priority of thread, thread priority example,
C# thread priority

C# THREAD PRIORITY 

“C# thread priority is the process of setting priority for the threads so that the can execute/perform their task as the priority specified is known as thread priority in multithreading. “
When we perform multithreading inc# then the CPU utilize its resources equally among all the thread and give equal time to execute that threads. Now the problem is if we have two different methods and that are executing by two different threads but the method one has to do more work than two in these case we can set the priority for the threads we can give specify more CPU resources to thread one to complete its work as compare to thread two, therefore we use thread priority in multithreading.
            We have five level of thread priority in multithreading
1.    Lowest
In this the level the selected thread consumes least CPU resources as compare to the all others to execute.
2.    Below Normal
After lowest this level will came. This level consume more CPU resources as compare to Lowest but less as compare to all others.
3.    Normal
The default priority of threads when we create threads then the CPU utilize its resources equally among the threads that is the Normal level.
4.    Above Normal
It consume more resources as compare to the above four but less resources as compare to highest level.
5.    Highest  
Last and powerful level in this level the selected thread consumes the highest resources of CPU as compare to the all others. It is used when a thread have to work more than all thread exist in program.

Syntax

            After instantiating child thread and specify its task, we can set the priority in such a way.
                [<Th>].Priority = ThreadPriority. <Level>
           Dot Priority = ThreadPriority. is the keyword in c# thread priority, where in place of <Th> the thread instance will come and in place of <Level> the five level which is detailed above will placed. If the syntax does work then try this one.
                [<Th>].Priority = System.Threading.ThreadPriority. <Level>;
Sometime the compiler does not recognize only ThreadPriority so don't vary about this error use the full syntax of System. Threading .ThreadPriority and then mention level

Feb 21, 2020

THREAD LOCKING C#


thread lock, c# lock keyword, c# lock static object,  c# lock keyword exaxmple, c# thread lock examples
c# thread lock

C# THREAD LOCK  

“C# thread lock is a process of locking of block of codes or resource to preventing the access of multiple threads for a same resource at a point of time”. 
    C# thread lock process play very important rule in multithreading ,when multiple user trying to access for a same resources of Data in Data Base System and Web Server System at a time.

Syntax of Thread locking

               To lock the blocks of code we use the keyword ‘Lock (this)’ and place the codes 
in-between starting and closing braces like given below, now once you lock the codes then that is accessable for only one thread at a time all the other thread have to wait in line to get acess to thoes code which is locked. C# thread lock syntax is
Lock (this)
{
  Statements;
  Or block of codes;
}

EXAMPLE OF THREAD LOCKING

            Suppose an example. That has a lock method accessing by different thread, make sure to add directive above of namespace that is ‘System. Threading’.
using System.Threading;
namespace ThraedLock
{
    class Program
    {
        public void ThreadLockdemo()
        {
            lock (this)
            {
                for (int i = 1; i <= 50; i++)
                    Console.WriteLine("Printing line number " + i );
            }
        }
        static void Main(string[] args)
        {
            Program p = new Program();
            Thread t1 = new Thread(p.ThreadLockdemo);
            Thread t2 = new Thread(p.ThreadLockdemo);
            Thread t3 = new Thread(p.ThreadLockdemo);
            t1.Start();
            t2.Start();
            t3.Start();
            Console.ReadKey();
        }
    }
}
       This program will program the line in sequence otherwise without using lock threading sequence will disturbed run it and see the outputs and then remove the lock body and see the output you will notice the changes.

MULTITHREADING JOIN METHOD IN C#

join method, c# join join method python, c# join example, thread join example
join in multithreading

JOIN METHOD IN MULTITHREADING IN C#

            “Join is the keyword which is used in multi-threading, when the Main Thread need to stay in program until the child threads does not complete their task”.

Syntax of Join method

<Thread-instance> Join ( );
            In between the brackets you can also specify the time to allow the Main thread go away from the program, if the specific thread does not complete its task in given time.  Like
<Thread-instance> Join (4000);

Why we use Join method in multithreading?

            In different project we have to make multiple child threads to execute different block of code as needed, but what happen in this process the Main Thread which is responsible to execute the entire program going to make child threads and itself exits form program, thus we want to stay the Main Thread until the child threads complete their task, we want that the Main thread should exist after all the child threads exited.

MULTITHREADING IN C#

multithreading,multithreading in java, c++ multithreading, multithreading in c,multic# thread example thread example
multitreading in c#

MULTITHREADING IN C#

            “Multiple threading is a process of using multiple threads in a project to execute different methods separately without waiting for one another”
            Basically by default all applications are single threaded model in which only one thread or only main thread executes all the instruction in sequence. If any problem such as server response or data base response delay due to any reason, then the entire program wait until the response without executing the rest of lines or method our program stay stuck in a method without executing the other methods. Therefore we use multiple threading in project to execute different method separately, if one method stuck for a while then all the rest method will execute without wasting time.

Syntax of Multithreading

    using System.Threading;
          Main function
      {
            Thread t1 = new Thread(METHOD NMAE);
            Thread t2 = new Thread(METHOD NAME);
            Thread t3 = new Thread(METHOD NAME);
            t1.Start();
             t2.Start();
             t3.Start();

    }

            First of all we have to include the System . Threading directive in our project after then we will instantiate the instance of Thread and will pass the method name as parameter that should execute through that thread, if the methods are non-static then in parameter section we also have to specify the instance of class in that class the specific method defines. At last we explicitly start the thread. See the example for more deep.

Feb 7, 2020

APPLICATION EXCEPTION IN C#


c# applicationexception, application exception overridden by rollback exception,applicationexception, exception application, exception in c#, exception
applicationexception c#

APPLICATION EXCEPTION

            “The Type of exception that define by programmer at the programming time for their own project, these exception is not predefined the system libraries these are built by programmer based on their own need.”

Steps to Define an Application Exception (Syntax)

            There are few step involve in Application exception definition.
        1.    Define a Class with a specific exception name and specify its return type.
[<Modifier>]  Class <Ex.Name>
{
   //;
}
        2.    Build inheritance with the Pre-defined Exception class, the parent may be system exception or any other class but the most prefer parent class will be Application Exception.
[<Modifier>]  Class <Ex.Name>: Application Exception  
{
   //;
}
        3.    Here the base class will be the Exception class because the Application Exception is further inherited by Exception class. There is a predefined virtual Massage method in Exception class override it by your own need method’s Massage. Also specify the return type usually it is string.
[<Modifier>]  Class <Ex.Name>: Application Exception  
{
   [<Modifier>] <Return> override Message ()
  {
    Statement;   //Here the massage will write that should display if the exception   
                           Rise by help of get accessor, see example below
   }
}
       4.    Now it’s time to call the exception, in case of system exception the CLR make instance and throw the exception for abnormal terminate, but here the programmer responsible to create the instance of exception and have to throw it explicitly. Like
By specifying the condition
If (condition)
{
   <Exception-Name> obj = new <Exception-Name> ( );
    Throw obj; 
}
But we can throw without creating instance name because we are not going to call any member of class so no need of instance name ‘obj’ simply you can do
If (condition)
{
   Throw new <Exception-Name> ( );
}

Throw

            Throw is a keyword which is used to throw the exception, see example for better understand.

Feb 2, 2020

EXCEPTION HANDLING


exception , exception handling in #, try catch finally javascript, c# throw exception, try catch c#,
exception handling

EXCEPTION IN C#

            “Exception is classes which is responsible for the abnormally terminating of a program due to runtime error.”
   We have two type of exception classes that's inherit exception as a base class. which is 
            1.   System-Exception 
            2.   Application-Exception 
   Why classes, see exception is not a one class it having multiple class for every error there is a class which responsible to handle that.  There are hundred exception classes. Some System-Exception classes are. 

  ð  Indexoutofbound exception

Index out of bound means we use a loop that execute for 5 times but we start it from 0 and went to 5, now there are total six iteration five will print our required result but how about the six one, here this exception class is responsible for the abnormal termination.

  ð  Dividebyzero exception

We know that no number can divide by zero if we try to do such thing in our program here immediately the divide by zero exception class will came into picture to cause the abnormal terminate of program.

  ð  Overflow exception

If any value that exceeding the size limit will give overflow.

  ð  Format exception

This class came into role when you trying to convert a double type value into integer or may be trying to convert string into double.
Exception handling            
            It is clear that what is exception and no it’s time see how exception is occur and to handle the exception means what we do when our program terminate abnormally without give the required output in run time.
            How the exception is occur see we all know that our programs runs in supervision of CLR inside when CLR found any mistake then it immediately make an instance that similar to any exception and send to that exception class when this class run our program terminate by displaying the relevant error message and exist flow of control without executing the remaining statements.
 Now once the abnormal terminate occurred we have a mechanism called as exception handling

EXCEPTION HANDLING IN C#

            “It is a process of stopping the abnormal termination of a program whenever runtime error is occur in program.”
            We can handle the exception by putting the code into two blocks
  ð  Try block
          In order to handle the exception we make to separate block, Try block is the first block or also call fitrst step to handle the exception. After making algorithm of problems we differentiate the statement that may cause the run time error and write all that statement or block of code in try block.  
  ð  Catch block
          Where the Catch block is used to write all those statement or block of code that should execute if the run time error is occur. Here we can display an user friendly massage or we also done an alternative action of the specific errors, such as if user enter an invalid value then by saying the actual value type we can regain the value.
try block, catch block, exception handling, try except, exception handling in c# try catch finally
try catch
Like this
try
 {
-       Statements;    //Here those statement require to write that cause the error and those that doesn’t require to run if the error occur.
  }
catch (<exception class name><variable>)
{
-       Statements;    //here the statement will write that have to execute when only there is a runtime error in program.
  }
In catch block either you display a message or done an alternative action for those error.

ERROR Compile time error, Runtime error

error, compile time error, runtime error, exception handling in java, python exception,
error

ERROR

            “Error is the mistake that makes a program not function properly”. In programming there are two types of error which can raise during programming that’s are
  ð  Compile time error
  ð  Runtime error