Posts

Showing posts from October, 2019

How to create TextBox in wpf that does not accept number using MVVM?

Image
Method 1: Using Model Property Inside View <TextBox Width="200" Text="{Binding MainWindowModel.NonNumeric,UpdateSourceTrigger=PropertyChanged}"> Inside Model  private string _nonNumeric;         public string NonNumeric         {             get { return _nonNumeric; }             set             {                 int intvalue;                 if (!int.TryParse(value[value.Length - 1].ToString(), out intvalue))                     SetProperty(ref _nonNumeric, value);                 else                     value = _nonNumeric;             }         } Method 2 : Using Command Inside View <Window x:Class="PrismDemo.Views.MainWindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"         xmlns:mc="http://schemas.openxmlf

How to create Own Semaphore?

 class CustomSemaphore     {         private Mutex[] arrMutex;         // place holder to store thread to mutex mapping         private Thread[] arrthread;         // number of threads allowed to access the resources         private int threadLimit;         // contructor creates the mutexes         public CustomSemaphore(int threadLimit)         {             this.threadLimit = threadLimit;             arrMutex = new Mutex[this.threadLimit];             arrthread = new Thread[this.threadLimit];             for (int i = 0; i < this.threadLimit; i++)             {                 arrMutex[i] = new Mutex();                 arrthread[i] = null;             }         }         public int Wait()         {             int index = WaitHandle.WaitAny(arrMutex);             if (index != WaitHandle.WaitTimeout)                 arrthread[index] = Thread.CurrentThread;             return index;         }         public void Release()         {             for

Write a method for division of two number without using division (‘/’) operator in C#.

    void DivideWithoutDivisionOperator(int divident,int divisior)         {             int quotient = 0;             bool isNegative = false;             if (divident < 0)//if negative             {                 divident = -divident;//make positive                 if (divisior < 0)//if negative                     divisior = -divisior;//make positive                 else                     isNegative = true;             }             else if (divisior < 0)//if negative             {                 divisior = -divisior;//make positive                 isNegative = true;             }             while(divident>=divisior)             {                 divident =divident- divisior;                 quotient++;             }             if (isNegative == true)//if negative                 quotient = -quotient;//make result as negative             Console.Write("Quotient"+quotient+" Reminder " + divident);         }