c# etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
c# etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

15 Kasım 2018 Perşembe

Thread Safe File Writing in C# (Wait On Lock) ReaderWriterLockSlim

public class Demo {
    private static ReaderWriterLockSlim _readWriteLock = new ReaderWriterLockSlim();

    public void WriteToFileThreadSafe(string text, string path) {
        // Set Status to Locked
        _readWriteLock.EnterWriteLock();
        try
        {
            // Append text to the file
            using (StreamWriter sw = File.AppendText(path))
            {
                sw.WriteLine(text);
                sw.Close();
            }
        }
        finally
        {
            // Release lock
            _readWriteLock.ExitWriteLock();
        }
    }
}
Kaynak: http://www.johandorper.com/log/thread-safe-file-writing-csharp




Reklam: www.evrenpehlivan.com


15 Ağustos 2018 Çarşamba

Foreach içerisindeki modeli post etme

for (var i = 0; i < Model.ToList< RequestCredit>().Count; i++)
{
@Html.HiddenFor(m => Model.ToList< RequestCredit>()[i].Id)


<div class="row" style="margin-bottom: 8px;">
<div class="col-sm-3" style="padding-top:7px;">
<h4 style="margin:0;">
@Html.DisplayFor(m => Model.ToList< RequestCredit>()[i].RequestPriceRangeText)
</h4>
</div>
<div class="col-sm-9">
@Html.TextBoxFor(m => Model.ToList< RequestCredit>()[i].RequestCreditAmount ,
new {@class="form-control", type = "number" })
</div>
</div>



Foreach içerisinde iterasyona tutulan Ienumerable listesi post edilirken sorun yaşandığında bu yöntem kullanılabilir.



6 Aralık 2013 Cuma

filling checkedListBox value member and text

  Filling checkedListBox
       
            List<CheckBoxItems> listCboxItems = new List<CheckBoxItems>();

            CheckBoxItems item = new CheckBoxItems();

            item.dataId = 1;
            item.Name = "evren";
            item.IsChecked = false;
            listCboxItems.Add(item);

            item = new CheckBoxItems();
            item.dataId = 2;
            item.Name = "ali";
            item.IsChecked = false;
            listCboxItems.Add(item);

           
            ((ListBox)this.checkedListBox1).DataSource = listCboxItems;
            ((ListBox)this.checkedListBox1).DisplayMember = "Name";
            ((ListBox)this.checkedListBox1).ValueMember = "dataId";

          for (int i = 0; i < checkedListBox1.Items.Count; i++)
            {
                CheckBoxItems obj = (CheckBoxItems)checkedListBox1.Items[i];
                checkedListBox1.SetItemChecked(i, obj.IsChecked);
            }

  Find out checked items

           foreach (CheckBoxItems item in checkedListBox1.CheckedItems)
            {
                string itemchecked = item.Name;
                MessageBox.Show(itemchecked); 
            }




 checkedListBox listItems class

    public class CheckBoxItems
    {
        public  bool IsChecked { get; set; }
        public  string Name { get; set; }
        public  int dataId { get; set; }
        public CheckBoxItems(){
           this.IsChecked = false;
        }

    }


evren pehlivan

http://www.tmrservisi.com/

filling checkedListBox value member and text, setting checkedListBox value member and text, populating checkedListBox value member and text, filling checkedListBox Items

22 Ağustos 2013 Perşembe

Getting string between strings in a line

private IEnumerable<string> GetSubStrings(string input, string start, string end)
{
   Regex r = new Regex(Regex.Escape(start) + "(.*?)" + Regex.Escape(end));
   MatchCollection matches = r.Matches(input);
         foreach (Match match in matches)
                yield return match.Groups[1].Value;
        }

8 Şubat 2013 Cuma

xml file to string

public static string m_xmlFileToString(string strFile)
        {
         
            XmlDocument xmlDoc = new XmlDocument();
            try
            {
                xmlDoc.Load(strFile);
            }
            catch (XmlException e)
            {
                Console.WriteLine(e.Message);
            }
         
            StringWriter sw = new StringWriter();
            XmlTextWriter xw = new XmlTextWriter(sw);
            xmlDoc.WriteTo(xw);
            return sw.ToString();
        }

6 Aralık 2012 Perşembe

c# dosya işlemleri

dosya uzantısını elde etmek için system.IO eklendikten sonra Path.GetExtension(this.FileUpload1.FileName) kullanılır.. (.jpg) gibi değer döndürür . dahil

2 Mart 2012 Cuma

My Sql Veritabanından Veri Okuma

Bu yazıda MySql Veri tabanında oluşturulmuş tablodan ComboBox'a veri aktarmayı inceleyeceğiz



1.Adım:

MySql Connector DLL dosyalarını Add reference kısmından ekledikten sonra mySql isimuzayı çağırılır

using MySql.Data.MySqlClient;
using MySql.Data;


2.Adım:

Veri tabanı bağlantı cümlesini get metoduyla çağırın

private string baglantiCumlesi
{ 
get {
return "Server=111.11.11.111;Database=VeriTabaniAdi;Uid=KullaniciAdi;Pwd=Şifre;";
}
}


3.Adım:
Tabloyla bağlantı ve comboBox a veri yükleme
       
MySqlConnection conn = new MySqlConnection(baglantiCumlesi);
        conn.Open();
        MySqlCommand cmd = new MySqlCommand("SELECT * FROM tabloAdi", conn);
        DataTable dt = new DataTable();
        MySqlDataReader dr = null;
        dr = cmd.ExecuteReader();
        dt.Load(dr);
        dr.Close();
        cBoxSiteler.DataSource = dt;
        cBoxSiteler.ValueMember = "no";
        cBoxSiteler.DisplayMember = "siteadi";
        conn.Close(); 

28 Şubat 2012 Salı

c# (Dataset) hücrenin içindeki veriyi okuma



dataset adı dataSet1 olsun


dataSet1.Tables["TabloAdı"].Rows[satırnumarası]["tablodakiSütunAdı"];




data table için de aynısı kullanılabilir.


txtBaslik.Text = datatable1.Rows[0]["baslik"].ToString();

Soyut Sınıfların Kullanımı

using System;
class Program
{
static void Main(string[] args)
{
sinifA nesne = new sinifA();
Console.Write(nesne.ozellik);
Console.Read();
}
}
class sinifA : SoyutSinif
{
public override int ozellik
{
get
{
return 5;
}
}
}
public abstract class SoyutSinif
{
public abstract int ozellik
{
get;
}
}

evren pehlivan yazılım

evren pehlivan yazılım, evren pehlivan yazılım geliştirici