Showing posts with label OOPS. Show all posts
Showing posts with label OOPS. Show all posts

Saturday, May 5, 2012

Inheritance


Class file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication1
{
    class inheritanc
    {
        private int mibalance;
        public int balance
        {
            get
            {
                return mibalance;

            }
            set
            {
                mibalance = value;
            }
        }
    }

    class inher : inheritanc
    {
        public void deposit(int amt)
        {
            balance = balance + amt;
        }
        public void withdraw(int amt)
        {
            balance = balance - amt;
        }
    }
}

Windows form file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class inheritance : Form
    {
        public inheritance()
        {
            InitializeComponent();
        }

     

        private void inheritance_Load(object sender, EventArgs e)
        {
            inheritanc kk=new inheritanc();
            MessageBox.Show(kk.balance.ToString());
        }
    }
}

aspx page creation


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication1
{
    public partial class createaspx : Form
    {
        public createaspx()
        {
            InitializeComponent();
        }
        StreamWriter sw;

        private void create_Click(object sender, EventArgs e)
        {
            sw = File.CreateText(@"E:\hello.aspx");
            sw.WriteLine("<html>");
            sw.WriteLine("<form runat=\"server\">");
            sw.WriteLine("<asp:button text=\"hello\" runat=\"server\"></asp:button>");
            sw.WriteLine("</form>");
            sw.WriteLine("</html>");
            sw.Close();
            System.Diagnostics.Process.Start(@"E:\hello.aspx");
        }
    }
}

Binary file creation





using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication1
{
    public partial class binaryfile : Form
    {
        public binaryfile()
        {
            InitializeComponent();
        }
        BinaryWriter bw;
        FileStream fs;
        BinaryReader br;
        private void button1_Click(object sender, EventArgs e)
        {
           
            fs = new FileStream(@"E:\demo.data", FileMode.Create);
            bw = new BinaryWriter(fs);
            for (int i = 0; i < 5; i++)
            {
                bw.Write(i);
               
            }
            bw.Close();
            MessageBox.Show("Binary file created successfully");

        }

        private void button2_Click(object sender, EventArgs e)
        {
            fs = new FileStream(@"E:\demo.data", FileMode.Open);
            br = new BinaryReader(fs);
            int l = (int)fs.Length;
            for (int i = 0; i < l / 4; i++)
            {
                listBox1.Items.Add(br.ReadInt32());
            }
        }
    }
}

File watcher





Properties->path->(C:\)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class filewatcher : Form
    {
        public filewatcher()
        {
            InitializeComponent();
        }

        private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
        {
            MessageBox.Show(e.Name);
        }

      
    }
}

String Format





using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class string_format : Form
    {
        public string_format()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show(string.Format("I am {0} specializing in {1}","sunitha",".net"));
            MessageBox.Show(string.Format("I am {0} specializing in {1} based at {2}","sunitha",".net","asp"));
        }
    }
}

Line number






using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication1
{
    public partial class linenumber : Form
    {
        public linenumber()
        {
            InitializeComponent();
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "Text file(*.txt)|*.txt";
            string filename;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                filename = openFileDialog1.FileName;
                int dr = 0;
                FileStream f = new FileStream(filename, FileMode.Open);
                StreamReader sr = new StreamReader(f);
                string line;
                StreamWriter sw = File.CreateText(@"E:\numbered.txt");
                while ((line = sr.ReadLine()) != null)
                {
                    dr++;
                    sw.WriteLine("{0}{1}", dr, line);
                }
                sw.Close();
                f.Close();
                MessageBox.Show("File numbered successfully");
                System.Diagnostics.Process.Start(@"E:\numbered.txt");

            }
        }
    }
}

Drive Extra Info





using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for Window5.xaml
    /// </summary>
    public partial class Window5 : Window
    {
        public Window5()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DriveInfo[] strdrives = DriveInfo.GetDrives();
            foreach (DriveInfo strdrive in strdrives)
            {
                listBox1.Items.Add(string.Format("Drive{0}",strdrive.Name));
                listBox1.Items.Add(string.Format("File type:{0}",strdrive.DriveType));
                listBox1.Items.Add(string.Format("Volume Label:{0}", strdrive.VolumeLabel));
                listBox1.Items.Add(string.Format("File System:{0}", strdrive.DriveFormat));
                listBox1.Items.Add(string.Format("Available space to current user:{0,15}bytes", strdrive.AvailableFreeSpace));
                listBox1.Items.Add(string.Format("Total available space:{0,15}bytes", strdrive.TotalFreeSpace));
                listBox1.Items.Add(string.Format("Total size of drive:{0,15}bytes", strdrive.TotalSize));


            }
        }
    }
}

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...