'Programming/C#'에 해당되는 글 2건

  1. 2011.12.25 How to shutdown a computer in c#
  2. 2011.10.19 Palindromic number source
Programming/C#2011. 12. 25. 02:06

The source codes seem like working only for Window OS 32bit, but 64 bit works perfectly The only problem is "privilege" That's the problem. we must run this application as an administration
01.ManagementBaseObject mboShutdown = null;
02.ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");
03.mcWin32.Get();
04.mcWin32.Scope.Options.EnablePrivileges = true;      // get security privileges
05.ManagementBaseObject mboShutdownParams = mcWin32.GetMethodParameters("Win32Shutdown");
06.mboShutdownParams["Flags"] = "1";
07.mboShutdownParams["Reserved"] = "0";
08.foreach (ManagementObject manObj in mcWin32.GetInstances())
09.{
10.    mboShutdown = manObj.InvokeMethod("Win32Shutdown", mboShutdownParams, null);
11.}
12.break;

'Programming > C#' 카테고리의 다른 글

Palindromic number source  (0) 2011.10.19
Posted by 박세범
Programming/C#2011. 10. 19. 02:01
.. too boring that's why I made this.

Actually, there are a lot of easier ways than the way that I did
I only use one library method, which is Math.pow

Here is the source code

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

namespace Practice
{
    public class Point
    {
        public static void Main()
        {
            for (int i = 0; i < 30000; i++)
            {
                if (Palindromic(i))
                    Console.WriteLine(i);
            }
        }

       public static bool Palindromic(int n)
       {
           // get how many digit we have
           //
           //int temp = n;
           int i;
           int temp;
           int digit = 0;
           for(temp = n;temp>0;digit++)  // get the number of digits.
           {
               temp /= 10;   
           }


           int firstDigit = 0;
           int secondDigit = 0;

           for(i=0;i<(digit/2);i++)
           {
               firstDigit = (n / (int)Math.Pow(10,i)) % 10;
               secondDigit = (n / (int)Math.Pow(10,digit-(i+1))) % 10;
               if(firstDigit != secondDigit)
                   break;
           }
           if (i == (digit / 2))
               return true;
           return false;
           
       }
           
    }
}

'Programming > C#' 카테고리의 다른 글

How to shutdown a computer in c#  (0) 2011.12.25
Posted by 박세범