Showing posts with label Microsoft. NET Framework. Show all posts
Showing posts with label Microsoft. NET Framework. Show all posts

Saturday, May 12, 2012

Method of simple iterations on C#

Hi, I needed to write this stuff for my vba project, but as I don't like vba I wrote it on C# so here you can get  my simple iterations method  code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication12
 {  
    class Program 
      {   
          public const int N = 3;  
          // simple iteration method procedure
          static public void ProstIterMetode(double[,]a, double[] d)
          {
             int i,j;
             double[] x0 = new double [N];
             double delta;
             double[] E = new double [N];
             double[] x = new double [N];
             x0=d;
     
            do {
                 for (i=0; i< N; i++)
                 {
                     x[i]=0;
                     for(j=0; j< N; j++)
                     {
                         x[i]=x[i]+a[i,j]*x0[j]; 
                     }
                     x[i]=x[i]+d[i];
                     E[i]=Math.Abs(x[i]-x0[i]); 
                 }
               delta=E[0];
               for (i=1; i< N; i++)
               {
                  if (delta<E[i]) delta=E[i];
               };
               x0=x; 
             } while(delta<=0.000001);
    
           for (i = 0; i < N; i++)
              Console.WriteLine(x[i]);
           } 


    static void Main(string[] args)
     {
       double[,] a = new double[N, N];
       double[] b = new double[N];
       double[] x = new double[N];
       for (int i = 0; i < N; i++)
         for (int j = 0; j < N; j++)
           a[i, j] = i+1; // Convert.ToDouble(Console.ReadLine());
      for (int i = 0; i < N; i++)
       {
         for (int j = 0; j < N; j++)
           Console.Write(a[i, j] + " ");
         Console.WriteLine();
       }
      
       Console.WriteLine("Input b");
       for (int i = 0; i < N; i++)
         b[i] = i + 1;//Convert.ToDouble(Console.ReadLine());       


       Console.WriteLine("Input x");
       for (int i = 0; i < N; i++)
         x[i] = i + 1; //Convert.ToDouble(Console.ReadLine());  
          
        ProstIterMetode(a, b);


           }
   }
 }

Friday, October 7, 2011

How to write tic tac toe on C# (C sharp)







Hi, now I will show you how to write tic tac toe on C# (C sharp).
First of all you need to add on Form 10 buttons and 4 labels.













The Form should look like this:








After that we will write some C# code:






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

namespace Tic_tac
{
    public partial class Form1 : Form
    {
        bool Player1 = true;
        bool Player2 = false;
        int X = 0;
        int O = 0;


        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button10_Click(object sender, EventArgs e)
        {
            button1.Text = "";
            button2.Text = "";
            button3.Text = "";
            button4.Text = "";
            button5.Text = "";
            button6.Text = "";
            button7.Text = "";
            button8.Text = "";
            button9.Text = "";
            
            Player1 = true;
            Player2 = false;
           

        }

       

        private void button1_Click(object sender, EventArgs e)
        {
            if (Player1 == true)
            {
                //Player1 = true;
                button1.Text = "X";
                Player1 = false;
            }
            else
            {
                Player2 = true;
                button1.Text = "O";
                Player2 = false;
                Player1 = true;
            }  
            Wincombination();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (Player1 == true)
            {
                //Player1 = true;
                button2.Text = "X";
                Player1 = false;
            }
            else
            {
                Player2 = true;
                button2.Text = "O";
                Player2 = false;
                Player1 = true;
            }
            Wincombination();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (Player1 == true)
            {
                //Player1 = true;
                button3.Text = "X";
                Player1 = false;
            }
            else
            {
                Player2 = true;
                button3.Text = "O";
                Player2 = false;
                Player1 = true;
            }

            Wincombination();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (Player1 == true)
            {
                //Player1 = true;
                button4.Text = "X";
                Player1 = false;
            }
            else
            {
                Player2 = true;
                button4.Text = "O";
                Player2 = false;
                Player1 = true;
            }

            Wincombination();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (Player1 == true)
            {
                //Player1 = true;
                button5.Text = "X";
                Player1 = false;
            }
            else
            {
                Player2 = true;
                button5.Text = "O";
                Player2 = false;
                Player1 = true;
            }

            Wincombination();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (Player1 == true)
            {
               // Player1 = true;
                button6.Text = "X";
                Player1 = false;
            }
            else
            {
                Player2 = true;
                button6.Text = "O";
                Player2 = false;
                Player1 = true;
            }

            Wincombination();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (Player1 == true)
            {
               // Player1 = true;
                button7.Text = "X";
                Player1 = false;
            }
            else
            {
                Player2 = true;
                button7.Text = "O";
                Player2 = false;
                Player1 = true;
            }

            Wincombination();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            if (Player1 == true)
            {
             //   Player1 = true;
                button8.Text = "X";
                Player1 = false;
            }
            else
            {
                Player2 = true;
                button8.Text = "O";
                Player2 = false;
                Player1 = true;
            }

            Wincombination();
        }

        private void button9_Click(object sender, EventArgs e)
        {
            if (Player1 == true)
            {
             //   Player1 = true;
                button9.Text = "X";
                Player1 = false;
            }
            else
            {
                Player2 = true;
                button9.Text = "O";
                Player2 = false;
                Player1 = true;
            }

            Wincombination();
        }

        private void Wincombination()
        {
            if (button1.Text == "X" && button2.Text == "X" && button3.Text == "X")
            {
                MessageBox.Show("X Win!", "Game over", MessageBoxButtons.OK);
                X = X + 1;
                label1.Text = X.ToString("");
            }
            if (button4.Text == "X" && button5.Text == "X" && button6.Text == "X")
            {
                MessageBox.Show("X Win!", "Game over", MessageBoxButtons.OK);
                X = X + 1;
                label1.Text = X.ToString("");
            }
            if (button7.Text == "X" && button8.Text == "X" && button9.Text == "X")
            {
                MessageBox.Show("X Win!", "Game over", MessageBoxButtons.OK);
                X = X + 1;
                label1.Text = X.ToString("");
            }

            if (button1.Text == "X" && button5.Text == "X" && button9.Text == "X")
            {
                MessageBox.Show("X Win!", "Game over", MessageBoxButtons.OK);
                X = X + 1;
                label1.Text = X.ToString("");
            }
            if (button3.Text == "X" && button5.Text == "X" && button7.Text == "X")
            {
                MessageBox.Show("X Win!", "Game over", MessageBoxButtons.OK);
                X = X + 1;
                label1.Text = X.ToString("");
            }

            if (button1.Text == "X" && button4.Text == "X" && button7.Text == "X")
            {
                MessageBox.Show("X Win!", "Game over", MessageBoxButtons.OK);
                X = X + 1;
                label1.Text = X.ToString("");
            }
            if (button2.Text == "X" && button5.Text == "X" && button8.Text == "X")
            {
                MessageBox.Show("X Win!", "Game over", MessageBoxButtons.OK);
                X = X + 1;
                label1.Text = X.ToString("");
            }
            if (button3.Text == "X" && button6.Text == "X" && button9.Text == "X")
            {
                MessageBox.Show("X Win!", "Game over", MessageBoxButtons.OK);
                X = X + 1;
                label1.Text = X.ToString("");
            }

            // for O

            if (button1.Text == "O" && button2.Text == "O" && button3.Text == "O")
            {
                MessageBox.Show("O Win!", "Game over", MessageBoxButtons.OK);
                O = O + 1;
                label2.Text = O.ToString("");
            }
            if (button4.Text == "O" && button5.Text == "O" && button6.Text == "O")
            {
                MessageBox.Show("O Win!", "Game over", MessageBoxButtons.OK);
                O = O + 1;
                label2.Text = O.ToString("");
            }
            if (button7.Text == "O" && button8.Text == "O" && button9.Text == "O")
            {
                MessageBox.Show("O Win!", "Game over", MessageBoxButtons.OK);
                O = O + 1;
                label2.Text = O.ToString("");
            }

            if (button1.Text == "O" && button5.Text == "O" && button9.Text == "O")
            {
                MessageBox.Show("O Win!", "Game over", MessageBoxButtons.OK);
                O = O + 1;
                label2.Text = O.ToString("");
            }
            if (button3.Text == "O" && button5.Text == "O" && button7.Text == "O")
            {
                MessageBox.Show("O Win!", "Game over", MessageBoxButtons.OK);
                O = O + 1;
                label2.Text = O.ToString("");
            }

            if (button1.Text == "O" && button4.Text == "O" && button7.Text == "O")
            {
                MessageBox.Show("O Win!", "Game over", MessageBoxButtons.OK);
                O = O + 1;
                label2.Text = O.ToString("");
            }
            if (button2.Text == "O" && button5.Text == "O" && button8.Text == "O")
            {
                MessageBox.Show("O Win!", "Game over", MessageBoxButtons.OK);
                O = O + 1;
                label2.Text = O.ToString("");
            }
            if (button3.Text == "O" && button6.Text == "O" && button9.Text == "O")
            {
                MessageBox.Show("O Win!", "Game over", MessageBoxButtons.OK);
                O = O + 1;
                label2.Text = O.ToString("");
            }


        }

        private void newGameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            button1.Text = "";
            button2.Text = "";
            button3.Text = "";
            button4.Text = "";
            button5.Text = "";
            button6.Text = "";
            button7.Text = "";
            button8.Text = "";
            button9.Text = "";

            Player1 = true;
            Player2 = false;
            X = 0;
            O = 0;
            label1.Text = "0";
            label2.Text = "0";
        }

        private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Tic-Tac-Toe 1.0 by Bogdan Ustyak");
        }
    }
}

ASP.NET








ASP.NET - technology for creating web applications and Web services from Microsoft. It is part of the Microsoft. NET and development of older technologies Microsoft ASP. Currently, the latest version of this technology is ASP.NET 4.0. 
ASP.NET outwardly retains much similarity with the older technology of ASP, which allows developers to relatively easily move to ASP.NET. At the same time the internal structure of ASP.NET is very different from ASP, as it is based on the platform. NET and, therefore, uses all the new possibilities offered by this platform.



History ASP.NET 


After releasing the server Internet Information Services 4.0 in 1997, Microsoft began to explore the possibility of a new model of Web applications that satisfy the complaints of ASP, particularly those associated with the separation of design from content, and which will write "clean" code. Work to develop such a model was assigned to Mark Anders, manager of the team IIS, and Scott Hutri who started work at Microsoft in 1997. Anders Hutri and developed the initial draft within two months, and wrote code Hutri initial prototype during the Christmas holidays of 1997. 
The initial project called «XSP»; Hutri explained in an interview in 2007 that "always ask what it means to the letter X. At that time it meant nothing. XML starts with her; XSLT starts with her. Everything cool starts with X, so we got the name. "Prototype of XSP was written in Java, but soon decided to build a new platform based on the Common Language Runtime (CLR), because it is present on the principles of OOP programming, garbage collection and other possibilities. Hutri described this decision as a "huge risk" because the success of the new development was linked to the success CLR, which, like XSP, was at an early stage of development.



Principles ASP.NET 


Even though ASP.NET takes its name from the old technology of Microsoft ASP, it differs significantly from it. Microsoft completely rebuilt ASP.NET, based on the Common Language Runtime (CLR), which is the foundation of all applications, Microsoft. NET. Developers can write code for ASP.NET, using virtually any programming language included in the kit. NET Framework (C #, Visual Basic.NET, and JScript. NET). ASP.NET has the advantage in speed compared to scripting technologies, so that when the first reference code is compiled and placed in a special cache, and then only performed without requiring the time for parsing, optimization, etc.



Advantages of ASP.NET to ASP 


   Compiled code is faster, most errors vidlovlyuyetsya still under construction 
   Much improved error handling run-time, using blocks try .. catch 
  Custom Controls (controls) allow you to highlight commonly used templates, such as site menu 
  Using metaphors, already used in Windows-applications, such as controls and events  
   Extensible set of controls and class libraries allows you to quickly develop applications 
   ASP.NET is based on the multilingual capabilities. NET, which allows you to write code      pages in VB.NET, Delphi.NET, Visual C / C + +, etc. 
  Ability to cache the entire page or part thereof to increase productivity 
  Possibility of caching data that are used on the page 
  Possibility of separation of visual and business logic from different files («code behind») 
  Extensible query processing model 
  The city expanded model 
  Extensible model of server controls 
  The presence of master-pages task templates pages 
  Support for CRUD-operations in a spreadsheet via GridView 
  Built-in support for AJAX 
  ASP.NET has the advantage in speed compared to other technologies, based on scripts. 
  You can give some comparison. Thus, ASP - derived from Win32, XML and HTML; PHP - from XML, HTML, Java, and CDI, then ASP.NET - from HTML and. NET (XML and XAML, respectively). However, if usually Rich Media Application created by Flash, now it is done with the module Silverlight, just because he ASP.NET. ASP.NET - richer environment for the development and deployment of web resources. In ASP.NET you can work with any. NET language, even to the Managed C + + and Visual Basic, which allows not to think about moving to C #. 


Expansion 


Microsoft has released several extensions to ASP.NET: 
ASP.NET AJAX 
ASP.NET MVC Framework



Microsoft. NET Framework



    Microsoft. NET (read dot-net) - software technology offered by Microsoft as a platform for creating both conventional programs and web applications. In many ways a continuation of the ideas and principles that are the technology of Java.
One of the ideas. NET is compatible services written in different languages. Although this opportunity is advertised as a benefit of Microsoft. NET, Java platform has the same opportunity.

    Each library (assembly) in. NET is a testimony of his version, which allows to eliminate possible conflicts between different versions of assemblies.
    .NET - cross-platform technology currently exists for the implementation of the Platform Microsoft Windows, FreeBSD (from Microsoft) and a variant of Linux technology for the project Mono (under an agreement between Microsoft with Novell), DotGNU [1].

    Copyright protection applies to a runtime (CLR - Common Language Runtime) for programs. NET. Compiler. NET produced by many companies for different languages ​​freely.

    . NET is divided into two main parts - the runtime (essentially a virtual machine) and development tools.
Development environment. NET-applications: Visual Studio. NET (C + +, C #, J #), SharpDevelop, Borland Developer Studio (Delphi, C #) and so is the Eclipse application development. NET-applications. Applicable program can also devise a text editor and use the command-line compiler.

    As technology is Java, development environment. NET generates byte code designed to perform a virtual machine. Input language of the machine in. NET is called CIL (Common Intermediate Language), also known as MSIL (Microsoft Intermediate Language), or just IL. The use of byte-code allows you krossplatformenist at precompiled project (in terms of. NET: collection), but not at the level of the original text, such as in C. Before starting the assembly in runtime (CLR) byte-code is converted into a built environment JIT-compiler (just in time, compiling on the fly) into machine code target processor.

    It should be noted that one of the first JIT-Compiler for Java was also developed by Microsoft (currently in Java using a multilevel perfect compilation - Sun HotSpot). Modern technology allows dynamic compilation to achieve the same level of performance with traditional 'static' compilers (like C + +) and performance issues often depends on the quality of a compiler.