Thursday 17 May 2018

File Stream in C# (How to read /write a text file in C#)





using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication21

{

    class Program

    {

        static void Main(string[] args)

        {

            FileStream F = new FileStream(@"C:\Users\salman\Desktop\FILE\salman.txt",FileMode.OpenOrCreate);

            Console.WriteLine("Enter the text :");

            string s = Console.ReadLine();

            byte[] ascii = Encoding.ASCII.GetBytes(s);

            foreach (byte item in ascii)

            {

                F.WriteByte(item);

            }



            Console.WriteLine("Data successfully written in file named as salman.txt");



            F.Close();





            Console.WriteLine("Press any key to read the same file............");

            Console.ReadKey();

            FileStream F2 = new FileStream(@"C:\Users\salman\Desktop\FILE\salman.txt", FileMode.OpenOrCreate);

            Console.ForegroundColor = System.ConsoleColor.Green;

            int i = 0;

            while ((i=F2.ReadByte())!=-1)

            {

                Console.Write((char)i);

            }

            Console.ReadKey();

            F2.Close();

       



        }

    }

}


Properties in C#







using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication20

{

    class Program

    {

        static void Main(string[] args)

        {

            EMPLOYEE EMP = new EMPLOYEE();

            Console.WriteLine("Enter the ID: ");

            EMP.ID = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter the name ");

            EMP.NAME = Console.ReadLine();

            Console.WriteLine("Enter the salary ");

            EMP.SALARY = float.Parse(Console.ReadLine());



            EMP.display();

     

        }

    }

}
-------------------------------------------------------------------------------------------

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

namespace ConsoleApplication20
{
    class EMPLOYEE
    {
        public int ID { get; set; }
        public string NAME { get; set; }

        public float SALARY { get; set; }
   
    public void display()
        {

            Console.WriteLine("ID: "+ID);
            Console.WriteLine("Name "+NAME);
            Console.WriteLine("Salary: "+SALARY);

        }
   
    }
}


struct in C#



using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication19

{

    class Program

    {

        static void Main(string[] args)

        {



            Rectangle r = new Rectangle(4,3);

            r.displayarea();

            Console.ReadLine();

        }

    }



    public struct Rectangle

    {

        int w, h;

        public Rectangle(int h, int w)

        {

            this.h = h;

            this.w = w;

        }



        public void displayarea()

        {



            Console.WriteLine("Area of Rectangle is "+(w*h));

        }



    }

}


Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...