Write a simple math program in C# and compile using C# compiler Windows 8

If you want to write a simple C# program or utility with 50-100 lines of code, for example, a program that printing “Hello World” on screen, set the date of a file or simple math quiz program (like the one below) you do not need to download any version of Visual Studio.

This article teaches you how to compile C# program using the C# compiler that comes with Windows 8. In order to demo this I have return a simple math quiz program.

You can copy the code below to compile in your Windows 8.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace ConAppMathWin8

{

  classProgram

  {

    staticvoid Main(string[] args)

    {

      //Declare for the ramdon number

      byte[] bytes1 = newbyte[50];

     

      int result = 0;

      int choose = 0;

      float answer = 0;

      float[] ansCollection = newfloat[5];

      Random rnd1 = newRandom();

      //Init the random number

      rnd1.NextBytes(bytes1);

      //Selct a choose

        Console.WriteLine(“========Play math========”);

        Console.WriteLine(“1. Add”);

        Console.WriteLine(“2. Subtract”);

        Console.WriteLine(“3. Multiply”);

        Console.WriteLine(“4. Divide”);

        Console.Write(“Choose: “);

        //Get the user input for choose

        try

        {

          choose = int.Parse(Console.ReadLine());

        }

        catch (Exception ex)

        {

          Console.WriteLine(“Error: {0}”, ex.ToString());

        }

 

      for (int i = 0; i < 5; i++)

      {

        switch(choose)

        {

          case 1:

            Console.Write(“What is the answer of {0} + {1} = “, bytes1[i], bytes1[i + 5]);

            //Storing result into array

            ansCollection[i] = Add(bytes1[i], bytes1[i + 5]);

            break;

          case 2:

            Console.Write(“What is the answer of {0} – {1} = “, bytes1[i], bytes1[i + 5]);

            //Storing result into array

            ansCollection[i] = Subtract(bytes1[i], bytes1[i + 5]);

            break;

          case 3:

            Console.Write(“What is the answer of {0} x {1} = “, bytes1[i], bytes1[i + 5]);

            //Storing result into array

            ansCollection[i] = Multiply(bytes1[i], bytes1[i + 5]);

            break;

          case 4:

            Console.Write(“What is the answer of {0} / {1} = “, bytes1[i], bytes1[i + 5]);

            //Storing result into array

            ansCollection[i] = Divide(bytes1[i], bytes1[i + 5]);

            break;

        }

        //Get input from player

        try

        {

        answer = float.Parse(Console.ReadLine());

        }

        catch (Exception ex)

        {

          Console.WriteLine(“Error: {0}”, ex.ToString());

        }

        //Add to counter if the answer is correct

        if (answer == ansCollection[i])

          result++;

      }

 

      Console.WriteLine(“******** Answer ************”);

      for (int i = 0; i < 5; i++)

      {

        //write answer

        Console.WriteLine(“Answer {0}: {1}”, i, ansCollection[i]);

      }

      Console.WriteLine(“%%%%%%%%%%%%%%%%%%%%”);

      //Write total correct answer(s)

      Console.WriteLine(“You got {0} correct!”, result);

      Console.ReadLine();

    }

 

    //Add 2 numbers

    publicstaticint Add(int i1, int i2)

    {

      return (i1+i2);

    }

    //Subtract 2 numbers

    publicstaticint Subtract(int i1, int i2)

    {

      return (i1-i2);

    }

    //Multiply 2 numbers

    publicstaticint Multiply(int i1, int i2)

    {

      return (i1*i2);

    }

    //Divide 2 numbers

    publicstaticfloat Divide(int i1, int i2)

    {

      return (i1/i2);

    }

  }

}

 

1. Copy the code above (if you do not have your own C# code).

2. Paste the above code to notepad and save as math.cs (if you copy the code).

3. Press Windows key and type cmd.

clip_image002

4. Go to the folder that you safe your file with cs extension, in our case math.cs.

5. Type c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc math.cs.

csc is the C# compiler.

6. You will find math.exe is generated.

7. Type the program name, math.exe, then the program will run.

Posted in .Net | Tagged , | Leave a comment

How to run batch file after TFS build

Where is the bat file actually located in TFS server after build.

In your TFS workflow you normally put the bat file to execute like

String.Format(“{0} \ SunMoon\scripts\cleandb.bat”, SourceDirectory);

 

 

 TFSWF1

In actual fact where is the physical path located in the TFS server. In order to know the path

1. Open Team Foundation Server Administrator Console.

2. Go to Build Configuration.

3. Open the Properties for the Agent and look at the Working Directory.

 

 

 TFSWF2

The directory is $(SystemDrive)\Builds means C:\Builds (unless your system drive is not C).

Posted in .Net | Tagged , | Leave a comment

How to test Jira REST API url using browser

When you read JIRA 5.0 REST API Documentation at https://developer.atlassian.com/static/rest/jira/5.0.html. The article is showing you to type

http://example.com:8080/jira/rest/api/2/application-properties

for example, if you use localhost as machine name then it will be

http://localhost:8080/jira/rest/api/2/application-properties

this is where your nightmare started.

The correct one should be

http://localhost:8080/rest/api/2/application-properties

without the the word “jira”.

Posted in .Net, Java | Tagged , , | Leave a comment

AMD Introduces the World’s Fastest Notebook Graphics Card

AMD today launched the AMD Radeon™ HD 8970M, the world’s fastest notebook graphics card[i]. The AMD Radeon HD 8970M graphics processing unit (GPU) delivers the best mobile gaming experience imaginable to gamers, powered by AMD’s award-winning Graphics Core Next (GCN) architecture.

“Today’s gaming notebooks need a graphics card that is fast, powerful and energy-efficient,” said Matt Skynner, corporate vice president and general manager, Graphics Business Unit, AMD. “The AMD Radeon HD 8970M GPU is the perfect combination of technologies, blending performance, immersive features and an extensive battery life that delivers an unrivaled gaming experience, even on the go.”


[i] The AMD Radeon HD 8970M is the world’s fastest notebook GPU. In tests by AMD as of 18th, April 2013, the reference AMD Radeon™ HD 8970M showed higher average performance than NVIDIA’s highest performing single GPU mobile graphics card, the GeForce® GTX 680M, in the 3DMark® Fire Strike test with a score of FS4571 vs. FS3749 and in Crysis 3 (FPS, 1080p at very high quality presets). System configuration: Intel® Core™ i7-3720QM (2.6GHz), 6GB DDR3-1600 and Windows 7 x64. AMD Radeon™ HD 8970M evaluated with AMD Catalyst™ 13.10 Beta 4. NVIDIA® GeForce® GTX 680M evaluated with NVIDIA® ForceWare™ 307.17 WHQL. GRM-4

Posted in Computers and Internet | Tagged | Leave a comment

ASUS ZenBook UX32VD Wi-Fi (Off) in Windows 8

You might realize your ASUS ZenBook UX32VD wi-fi is off in Windows 8 and cannot turn back On using Fn + F2. Do the 3 steps below.

 

1. Plug in your Network cable.

2. Remove the Intel Wi-Fi driver from Device Manager.

3. Reboot your ZenBook.

 

Your Wi-Fi driver should be detected and reinstalled automatically and the Wi-Fi (On).

Posted in Computers and Internet, Operating System | Tagged , , | Leave a comment

Using Web API with Entity Framework to retrieve data sample

Refer to Creating ADO.NET Entity Data Model in VS 2012, we have created an ADO.NET Entity Data Model. Use the same method to add an ADO.NET Entity Data Model to your project.

 

1. Open ValuesController.cs file under the Controllers folder in Solution Explorer.

 

2. Replace the entire Get() method with the following code. 

 

publicList<Product> Get()

{

  northwindEntities ctx = newnorthwindEntities();

  //select all the products

  var result = from r in ctx.Products select r;

  //return the product as list

  return result.ToList();

}

 

3. Open Index.cshtml file under the Views \ Home folder in Solution Explorer.

4. Replace the entire file with the following code.

<!DOCTYPEhtml>

<htmlxmlns=”http://www.w3.org/1999/xhtml”&gt;

<head>

 

  <scriptsrc=”Scripts/jquery-1.7.1.min.js”></script>

  <scriptsrc=”Scripts/jquery-1.7.1.js”></script>

 

  <scripttype=”text/javascript”>       

    $(document).ready(function () {

      $.getJSON(“/api/Values”,   

          function (data) {                    

            $.each(data, function (i, item) {                                     

              $(“#test”).append(item.ProductName + “<br />”);

             

            });

          });

    });

 

  </script>

 

  <title></title>

</head>

<body>

  <divid=”test”></div>

</body>

</html>

 

Download the complete code from http://skydrive.live.com. The sample file name is MvcApp2.rar. My MSN ID is chanmmn@hotmail.com.

Posted in .Net | Tagged , | Leave a comment

AMD Unleashes the World’s Fastest Graphics Card

SUNNYVALE, Calif. — April 24, 2013 AMD (NYSE: AMD) today launched the AMD Radeon™ HD 7990, the world’s fastest graphics card[i], designed for gamers who want to take their PC gaming experience to the highest level. Based on award-winning AMD Graphics Core Next (GCN) architecture with AMD Eyefinity technology[ii], the AMD Radeon HD 7990 graphics card delivers unrivaled performance and world-class technology for playing the latest DirectX® 11 games in extreme resolutions and multi-monitor configurations.

“If you crave the ultimate in PC gaming, the clear and commanding choice is the Radeon HD 7990 graphics card. No other graphics card on the market measures up to the unparalleled gaming experience it delivers, and it comes with eight AAA game titles optimized for AMD Radeon award-winning GCN architecture,” said Matt Skynner, corporate vice president and general manager, Graphics Business Unit, AMD. “Once again, AMD shatters the industry benchmark for state-of-the-art graphics technology.”


[i]In tests by AMD as of 28 February, 2013, the AMD Radeon™ HD 7990 showed higher average performance than the NVIDIA® GeForce® GTX 690 in the 3DMark® Fire Strike Extreme (FS6407 vs. FS5316) and Crysis 3 (1080p & 1600p at all quality presets). System configuration: Intel® Core™ i7-3960X (3.30 GHz), MSI X79A-GD65, 16GB DDR3-1600 and Windows 8 x64. AMD Radeon™ HD 7990 evaluated with AMD Catalyst™ 13.2 Beta 6. NVIDIA® GeForce® GTX 690 evaluated with NVIDIA® ForceWare™ 310.90 WHQL. GRDT-32

[ii]AMD Eyefinity technology supports up to six DisplayPort monitors on an enabled graphics card.  Supported display quantity, type and resolution varies by model and board design; confirm specifications with manufacturer before purchase.  To enable more than two displays, DisplayPort™-ready monitors are strongly recommended. Maximum two active DisplayPort adapters supported. Additional hardware may be required; see www.amd.com/eyefinityfaq for full details.

Posted in Community, Computers and Internet | Tagged | Leave a comment