There are huge collections of base classes in .Net, i.e. approximately 3400 classes and there are also a large number of namespaces that contain these classes. We can’t give you the complete coverage of these namespaces and base classes of .Net, but we’ll give you a quick summary of some of the more useful namespaces here. | ||||||||||||||||||||
|
||||||||||||||||||||
There are many more namespaces, and the best way to learn about them and the classes they contain is to explore them yourself. | ||||||||||||||||||||
Practical Example: | ||||||||||||||||||||
Steps: | ||||||||||||||||||||
? Create windows project. ? Default namespace has been created. ? Add new namespace out of the scope of default namespace. ? Using created namespace name with using directive. |
||||||||||||||||||||
Form1.cs[Design] | ||||||||||||||||||||
Form1.cs | ||||||||||||||||||||
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using myClass; namespace testCustomNamespace { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { textBox3.ReadOnly=true; } private void button1_Click(object sender, EventArgs e) { if (textBox1.Text != "" && textBox1.Text != "First Number") { if (textBox2.Text != "" && textBox2.Text != "Second Number") { myClass.abc aa = new abc(); int res = aa.addnum(int. Parse(textBox1.Text), int.Parse(textBox2.Text)); textBox3.ReadOnly = false; textBox3.Text = res.ToString(); } else { MessageBox.Show("Please enter second number.", "eBIZ Tutorial", MessageBoxButtons.OK, MessageBoxIcon.Information); textBox2.Focus(); } } else { MessageBox.Show("Please enter first number.", "eBIZ Tutorial",MessageBoxButtons.OK,MessageBoxIcon.Information); textBox1.Focus(); } } private void textBox1_Click(object sender, EventArgs e) { textBox1.SelectAll(); } private void textBox2_Click(object sender, EventArgs e) { textBox2.SelectAll(); } private void button2_Click(object sender, EventArgs e) { textBox1.Text = ""; textBox1.Text = "First Number"; textBox2.Text = ""; textBox2.Text = "Second Number"; textBox3.Text = ""; textBox3.Text = "Click on Add button to find result."; } } } namespace myClass { class abc { public int addnum(int x, int y) { int c = x + y; return c; } } } |
||||||||||||||||||||
Program.cs | ||||||||||||||||||||
using System; using System.Collections.Generic; using System.Windows.Forms; namespace testCustomNamespace { static class Program { /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } } |
||||||||||||||||||||
The Output is: | ||||||||||||||||||||