stackoverflow1453

Programming&&Games&&Life

Archive for March, 2016

Multithreading-1

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

namespace Thr
{
    class Program
    {
        static void Main(string[] args)
        {
            Thread th = Thread.CurrentThread;
            th.Name = "Mainss";
            Console.WriteLine("This is {0}",th.Name);
            Console.WriteLine("This is {0}", th.ThreadState);
        }
    }
}

delegate – 3

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

namespace ConsoleApplication39
{
    class Program
    {
        public delegate int t(int m);  //carp
        public delegate int z(int n);  //topla

        public int carp(int z)
        {
            return z * 2;
        }

        public int topla(int j)
        {
            return j++;
        }

        static void Main(string[] args)
        {
            Program p = new Program();
            t t1 = new t(p.carp);
            Console.WriteLine(t1(2));

            t t2 = new t(p.topla);
            Console.WriteLine(t2(5));
        }
    }
}

How to write a C program in Visual Studio ?

Using Microsoft Visual Studio for Simple C Programs

A free version of Microsoft Visual C++ Express is available in: http://msdn2.microsoft.com/en-us/express/aa700735.aspx

To edit your C program:

  1. From the main menu select File -> New -> Project
  2. In the New Project window:
    Under Project types, select Win32 – Win32 Console Application
    Name your project, and specify a location for your project directory
    Click ‘OK’, then ‘next’
  3. In the Application Wizard:
    Select Console application
    Select Empty project
    Deselect Precompiled header
  4. Once the project has been created, in the window on the left hand side you should see three folders:
    Header Files
    Resource Files
    Source Files
  5. Right-click on Source Files and Select Add-> New Item
    Select Code, and give the file a name
    The default here will be a file with a *.cpp extension (for a C++ file). After creating the file, save it as a *.c file.

To compile and run:

  1. Press the green play button.
  2. By default, you will be running in debug mode and it will run your code and bring up the command window.
    To prevent the command window from closing as soon as the program finishes execution, add the following line to the end of your main function:
    getchar();
    This library function waits for any input key, and will therefore keep your console window open until a key is pressed.

Source: http://www.swarthmore.edu/NatSci/tali/E15/Visual_C.html