X
تبلیغات
عشق من سی شارپ

عشق من سی شارپ
عشق من سی شارپ 

Easy writing all text to a file

WriteAllText will create the file if it doesn't exist, otherwise overwrites it. It will also close the file.

 
using System;
namespace PlayingAround {
    class ReadAll {
        public static void Main(string[] args) {
            string myText = "Line1" + Environment.NewLine + "Line2" + Environment.NewLine;
            System.IO.File.WriteAllText(@"C:\t2", myText);
        }
    }
}
[ چهارشنبه چهارم اسفند 1389 ] [ 20:14 ] [ علی احمدی ] [ ]

Read an entire file into a string

using System;
namespace PlayingAround {
    class ReadAll {
        public static void Main(string[] args) {
            string contents = System.IO.File.ReadAllText(@"C:\t1");
            Console.Out.WriteLine("contents = " + contents);
        }
    }
}
[ چهارشنبه چهارم اسفند 1389 ] [ 20:13 ] [ علی احمدی ] [ ]

Read a file with a single call to sReader.ReadToEnd() using streams

 
public static string getFileAsString(string fileName) {
   StreamReader sReader = null;
   string contents = null;
   try {
      FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
      sReader = new StreamReader(fileStream);
      contents = sReader.ReadToEnd();
   } finally {
     if(sReader != null) {
         sReader.Close();
      }
   }
   return contents;
}
[ چهارشنبه چهارم اسفند 1389 ] [ 20:13 ] [ علی احمدی ] [ ]

Read all the lines from a file into an array

 
using System;
namespace PlayingAround {
    class ReadAll {
        public static void Main(string[] args) {
            string[] lines = System.IO.File.ReadAllLines(@"C:\t1");
            Console.Out.WriteLine("contents = " + lines.Length);
            Console.In.ReadLine();
        }
    }
}
[ چهارشنبه چهارم اسفند 1389 ] [ 20:13 ] [ علی احمدی ] [ ]

Read a file line by line with no error checking

Useful if the file may be really large.

 
StreamReader sr = new StreamReader("fileName.txt");
string line;
while((line= sr.ReadLine()) != null) {
	Console.WriteLine("xml template:"+line);
}

if (sr != null)sr.Close();  //should be in a "finally" or "using" block
[ چهارشنبه چهارم اسفند 1389 ] [ 20:13 ] [ علی احمدی ] [ ]

The obligatory example for any language,

 
using System;
public class HelloWorld
{
    public static void Main(string[] args) {
            Console.Write("Hello World!");
    }
}

Raw CSharp compiler

You can compile c# using the command line version
C:>csc HelloWorld.cs

and then run the new program by entering

HelloWorld

You can get Nant, a build tool like the old 'make', from http://sourceforge.net/projects/nant.

Reference By http://www.fincher.org/tips/Languages/csharp.shtml

[ چهارشنبه چهارم اسفند 1389 ] [ 20:5 ] [ علی احمدی ] [ ]

Ebteda bayad shoma yek List as Data Sort shode dashteh bashin masalan
 
"Absulate" , "Bita", "Cry" , "Dry" , "Erase" , "Feel"
 
mikhahim yek Onsor ro ba Binary Search konim
 
tarif Array in C#
string [] names = new string[] {"Absulate" , "Bita", "Cry" , "Dry" , "Erase" , "Feel"};
 
 
man dar zir Binary Search ro be sorat Adadi darj kardam.
================
 
using System;
 
class ArrayBinarySearch
{
   public static void Main()
   {
      int[] ints = {0, 10, 100, 1000, 1000000 };
      Console.WriteLine ("Array indices and elements: ");
      for (int i = 0; i < ints.Length; i++ )
      {
         Console.Write("[{0}]={1, -5}", i, ints[i]);
      }
      Console.WriteLine();
      FindObject  (ints, 25);
      FindObject  (ints, 1000);
      FindObject  (ints, 2000000);
   }
  
   public static void FindObject  (Array array, Object o)
   {
      int index = Array.BinarySearch (array, 0, array.Length, o);
      Console.WriteLine();
      if (index > 0 )
      {
         Console.WriteLine ("Object: {0} found at [{1}]", o, index );
      }
      else if (index == array.Length )
      {
         Console.WriteLine ("Object: {0} not found. "
            + "No array object has a greater value." , o);
         Console.WriteLine ();
      }
      else
      {
        Console.WriteLine ("Object: {0} not found. "
           + "Next larger object found at [{1}].", o, ~index);
      }
   }
}
 
=========
 
kafie shoma array adadi ro be String tabdil konin
javab hale

[ یکشنبه نوزدهم خرداد 1387 ] [ 19:9 ] [ علی احمدی ] [ ]

این هم یه برنامه برای تبدیل postfix to infix

#include "graphics.h"
#include "conio.h"
#include "iostream.h"
#include "time.h"
#include "stddef.h"
#include "stdio.h"
#include "dos.h"
#include "string.h"
#include "ctype.h"
#include "stdlib.h"
const size=1000;
//***********************************//
static int choise,driver=DETECT,mode=0,i;
//***********************************//
// Start Graphic class
class Graphic
{
     public:
   void Graph();
   int BackGround();
   void Title();
   void Head();
   void Time();
   void Sign();
   void PostfixMenu();
   //void PrefixMenu();
   void HelpMenu();
     private:
   static void box(int,int,int,int,int);
   static void fill_box(int,int,int,int,int);
}GraphObject;
//***********************************// End Class Graphic


ادامه مطلب
[ شنبه چهارم خرداد 1387 ] [ 15:3 ] [ علی احمدی ] [ ]

سلام دوستان

این هم کد یه برنامه بانک البته کامل نیست

#include "graphics.h"
#include "conio.h"
#include"iostream.h"
#include "time.h"
#include "stddef.h"
#include "stdio.h"
#include "dos.h"
#include "fstream.h"
#include "string.h"
//***********************************//
void box(int,int,int,int);
static int choise,driver=DETECT,mode=0,i;
static char save1,save2;
//***********************************//
class banck
{
  public:
    void onemenu();
    void EftetaheHesab();
    void towmenu();
    void daryaftmojodi();
    int graph();
}banckshaey;
//***********************************//


ادامه مطلب
[ یکشنبه پانزدهم مهر 1386 ] [ 15:6 ] [ علی احمدی ] [ ]

این هم سایتهای جالب سی شارپ:

http://www.csharp-station.com/
http://csharp-source.net/
technorati.com/tag/csharp
www.csharp-corner.com
www.c-sharpcorner.com
www.csharpfriends.com

[ جمعه سیزدهم بهمن 1385 ] [ 19:57 ] [ علی احمدی ] [ ]
.: WebSiteThemes By Cshart :.

درباره وب سایت

جستجو
Google

در اين وبلاگ
در كل اينترنت
آخرين مطالب
موضوعات وب
امکانات وب

.