Tuesday 25 June 2013

How to find single value from string in c#

         You can use this code for  find single value from string


        const string stringValue = "1,16,12,113";
            string result = "";
            const string yourValue = "1"; //Assiged the user input value
            string[] arr = stringValue.Split(new char[] { ',' });//Convert string to string array
            foreach (string value in arr)
            {
                if (value == "" + yourValue + "") // condition checked for matching your value  in string array
                {
                    result = value; //assign the matched value
                    break; // then go to out side of for each
                }
            }
            string finalResult = result; //finally assigend the matching value


My above code is working fine .but i used foreach ,it's not a good performance ,so we can use findall
see below code and try this

const string stringValue = "1,16,12,113";
string finalValue = "";
const string yourValue = "1"; //Assiged the user input value
string[] arr = stringValue.Split(new char[] { ',' });//Convert string to string array
var results = Array.FindAll(arr, s => s.Equals(yourValue));//if your value there ,then we assigned that value in array
if (results.Length != 0)
    {
      finalValue = results[0];//finay we got a value
    }

Convert string to string array in c#

here is a simple example for convert string to string array


            string values= "1,16,12,113";
            string[] arr = values.Split(new char[] { ',' }); //Convert string to string array using split 

Monday 24 June 2013

How to create a simple WPF application

In Visual Studio 2008 OR any 


  • Open Visual Studio 2008 and choose "File", "New", "Project..." in the main menu. Choose "WPF Application" as project type.
  • Choose a folder for your project and give it a name. Then press "OK"


  • Visual Studio creates the project and automatically adds some files to the solution. A Window1.xaml and an App.xaml. The structure looks quite similar to WinForms, except that the Window1.designer.cs file is no longer code but it's now declared in XAML as Window1.xaml


  • Select the Button and switch to the event view in the properties window (click on the little yellow lightning icon). Doubleclick on the "Click" event to create a method in the codebehind that is called, when the user clicks on the button.

Note: If you do not find a yellow lightning icon, you need to install the Service Pack 1 for VisualStudio on your machine. Alternatively you can doubleclick on the button in the designer to achieve the same result.

  • Visual Studio automatically creates a method in the code-behind file that gets called when the button is clicked.
private void button1_Click(object sender, RoutedEventArgs e)
{
    textBox1.Text = "Hello WPF!";
}


  • The textbox has automatically become assigned the name textBox1 by the WPF designer. Set text Text to "Hello WPF!" when the button gets clicked and we are done! Start the application by hit [F5] on your keyboard.





Saturday 8 June 2013

difference between margin and padding in css

padding is the space between the content and the border, whereas margin is the space outside the border. Here's an image I found from a quick Google search, that illustrates this idea.



How to reduce angular CLI build time

 Index: ----- I am using angular cli - 7 and I am going to tell how to reduce the build time as per my knowledge. Problem: -------- Now the ...