Multi-threading in C#

A simple mult-threading in c# .

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class MyThread
    {
        public static void Main(String[] args)
        {
            Console.WriteLine("Threading test : ");


            Task1 t_one = new Task1();
            t_one.num = 5;

            //Thread one
            Thread thread1 = new Thread(t_one.Print);
            thread1.Name = "Thread 1";
            thread1.Start();

            //Thread two
            Thread thread2 = new Thread(t_one.Print);
            thread2.Name = "Thread 2";
            thread2.Start();

            thread1.Join();
            thread2.Join();

            Console.WriteLine("All done");

            Console.ReadKey();
        }
    }

    class Task1
    {
        public int num;

        public void Print()
        {
           
            for(int i=0;i< num;i++)
            {
                Console.WriteLine(Thread.CurrentThread.Name + " : " + i);
                Thread.Sleep(1000);
            }
            Console.WriteLine(Thread.CurrentThread.Name +" done");
        }
    }
}

Function Pointers inside Struct in C

#include <stdio.h>

typedef struct{
	int x;
	int y;
	int (*addXPoints) (int x,int y);
	int (*subXPoints) (int x,int y);
}Point;

int addPoints_x(int p1, int p2)
{
		return (p1+p2);
}	

int subtracteXPoints(int p1,int p2)
{
		return (p1-p2);
}

void printPointDetails(Point* temp)
{
		printf("Point [x,y] : %d , %d \n", temp->x, temp->y);
}

int main()
{
	Point p1={30,30};
	
	//another way to initialize
	//p1.x=10; 
	//p1.y=20;
	p1.addXPoints=addPoints_x;
	p1.subXPoints=subtracteXPoints;
	
	printPointDetails(&p1);
	
	printf("Total X Value of p1,p2 : %d\n",p1.addXPoints(p1.x,p1.x));
	printf("Total X Value of p1,p2 : %d\n",p1.subXPoints(p1.x,p1.x));
	

	return 0;
}

Constant pointers and Pointers to constant in C

#include <stdio.h>
int main()
{
	int val = 250;
	int val2 =300;

        // ptrInt is a pointer to integer constant
        const int* ptrInt = &val; //Pointer to Constant

        // ptrInt1 is a constant pointer to integer
        int* const ptrInt1 = &val; //Constant Pointer

        *ptrInt = 500; //pointer to constant wont allow

	ptrInt1 = &val2; //constant pointer wont allow

	return 0;
}