So I built a simple program where the user will enter the pet's name and age and when they click the button it will simply grab that information and display it in the label fields but i am so confused. Can anyone help me out?
using System;
using System.Collections.Generic;using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Pet_s_Name
{
public partial class MainWindow : Window
{
private void Click_Click(object sender, RoutedEventArgs e)
{
//Fields should always be private
private string _name;
private int _age;
//Properties
public string Name
{
get { return _name; }
set { _name = value; }
}
public int Age
{
get{ return _age;}
set { _age = value; }
}
//Constructor
public Pet(string nam, int ag)
{
_name = nam;
_age = ag;
}
}
}
}
}
}
VulpesPosted Aug 12, 2014, 5:37 AM
To do this go to the Project menu -> Add Class and create a file called Pet.cs.
You can then add your code to that file:
Returning now to your MainWindow class, I'm assuming that the user will input the pet's name and age separated by a single space in the texbox and when the button is clicked a Pet object will be created from this input and used to populate the labels. The code for that would be:
Ankur JainPosted Aug 11, 2014, 11:31 PM
Thank you for posting in c# corner, but i didn't get your question, please brief your question, confusion or problem that you are facing in above posted code. Thank you!