Guest User

Dot_Net Practicals

a guest
Jun 24th, 2018
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.34 KB | None | 0 0
  1. #practical 1
  2.  
  3. using System;
  4.  
  5. namespace ConsoleApplication1
  6. {
  7. class Ones
  8. {
  9. static void Main(string[] args)
  10. {
  11. Console.Write("Enter a Number : ");
  12. string a = Console.ReadLine();
  13. int len = a.Length;
  14. int n = Convert.ToInt32(a);
  15. int count = 0;
  16. int m = 0;
  17. for (int i = 0; i < len; i++)
  18. {
  19. m = n % 10;
  20. n = n / 10;
  21. if (m == 1)
  22. {
  23. count = count + 1;
  24. }
  25. }
  26. Console.WriteLine("Number of 1's: " + count);
  27. }
  28. }
  29. }
  30.  
  31.  
  32. #parctical 3
  33.  
  34. using System;
  35. using System.Collections.Generic;
  36. using System.Linq;
  37. using System.Text;
  38.  
  39. namespace ConsoleApplication1
  40. {
  41. class Userpass
  42. {
  43. public static void Main(string[] args)
  44. {
  45. String user = "dotnet";
  46. String pass = "technologies";
  47. Console.Write("Enter Username: ");
  48. String userin = Console.ReadLine();
  49. Console.Write("Enter Password: ");
  50. String passin = Console.ReadLine();
  51.  
  52. if (userin == user && passin == pass)
  53. {
  54. Console.WriteLine("Congratulation Access Granted");
  55. }
  56. else
  57. {
  58. Console.WriteLine("Username or Password is Incorrect");
  59. }
  60. }
  61. }
  62. }
  63.  
  64. #practical 5
  65.  
  66. using System;
  67. using System.Collections.Generic;
  68. using System.Linq;
  69. using System.Text;
  70.  
  71. namespace ConsoleApplication3
  72. {
  73. class StringMem
  74. {
  75. static void Main(string[] args)
  76. {
  77. String s1 = "DotNet Technologies";
  78. Console.Write("Enter the string to check : ");
  79. String s2 = Console.ReadLine();
  80. Console.WriteLine(s1.Contains(s2));
  81.  
  82. Console.Write("\n\nEnter the string to insert : ");
  83. String s3 = Console.ReadLine();
  84. Console.Write("Enter the Loaction of Insertion of String : ");
  85. int loc1 = Int32.Parse(Console.ReadLine());
  86. Console.WriteLine(s1.Insert(loc1-1,s3));
  87.  
  88. Console.Write("\n\n Enter the StartIndex of Removal of String : ");
  89. int loc2 = Int32.Parse(Console.ReadLine());
  90. Console.Write("Enter the Number of Characters to Remove : ");
  91. int num = Int32.Parse(Console.ReadLine());
  92. Console.WriteLine(s1.Remove(loc2 - 1, num));
  93.  
  94. Console.Write("\n\nEnter the existing string : ");
  95. String s4 = Console.ReadLine();
  96. Console.Write("Enter the string to replace: ");
  97. String s5 = Console.ReadLine();
  98. Console.WriteLine(s1.Replace(s4, s5));
  99.  
  100. }
  101. }
  102. }
  103.  
  104.  
  105. #practical 8
  106.  
  107. using System;
  108. using System.Collections.Generic;
  109. using System.ComponentModel;
  110. using System.Data;
  111. using System.Drawing;
  112. using System.Linq;
  113. using System.Text;
  114. using System.Windows.Forms;
  115.  
  116. namespace WindowsFormsApplication1
  117. {
  118. public partial class Form1 : Form
  119. {
  120. public Form1()
  121. {
  122. InitializeComponent();
  123. }
  124.  
  125. private void Form1_Load(object sender, EventArgs e)
  126. {
  127.  
  128. }
  129.  
  130. private void user_Click(object sender, EventArgs e)
  131. {
  132.  
  133. }
  134.  
  135. private void usertext_TextChanged(object sender, EventArgs e)
  136. {
  137.  
  138. }
  139.  
  140. private void Passtext_TextChanged(object sender, EventArgs e)
  141. {
  142.  
  143. }
  144.  
  145. private void reset_Click(object sender, EventArgs e)
  146. {
  147. usertext.Clear();
  148. Passtext.Clear();
  149. }
  150.  
  151. private void Submit_Click(object sender, EventArgs e)
  152. {
  153. string user = usertext.Text;
  154. string pass = Passtext.Text;
  155.  
  156. if (user.Equals("") && pass.Equals(""))
  157. {
  158. MessageBox.Show("Fields Cannot be left blank");
  159. }
  160. else if (user.Equals("dotnet") && pass.Equals("technologies"))
  161. {
  162. MessageBox.Show("Access Granted");
  163. this.Close();
  164. }
  165. else
  166. {
  167. MessageBox.Show("Username or Password is Incorrect");
  168. usertext.Clear();
  169. Passtext.Clear();
  170. }
  171. }
  172.  
  173. private void Loglab_Click(object sender, EventArgs e)
  174. {
  175.  
  176. }
  177. }
  178. }
  179.  
  180. #practical 9
  181.  
  182. **Form 1
  183.  
  184. using System;
  185. using System.Collections.Generic;
  186. using System.ComponentModel;
  187. using System.Data;
  188. using System.Drawing;
  189. using System.Linq;
  190. using System.Text;
  191. using System.Windows.Forms;
  192.  
  193. namespace WindowsFormsApplication2
  194. {
  195. public partial class Form1 : Form
  196. {
  197. public Form1()
  198. {
  199. InitializeComponent();
  200. }
  201.  
  202. private void CalDOB_ValueChanged(object sender, EventArgs e)
  203. {
  204.  
  205. }
  206.  
  207. private void chkbtn_Click(object sender, EventArgs e)
  208. {
  209. int yy = int.Parse(yrtext.Text);
  210. int mm = int.Parse(mnthtext.Text);
  211. int dd = int.Parse(datetext.Text);
  212. DateTime d1=DateTime.Now ;
  213. DateTime d2 = new DateTime(yy,mm,dd);
  214. TimeSpan difference = d1.Subtract(d2);
  215. double dif = (difference.TotalDays/365.25);
  216.  
  217. if (dif >= 18)
  218. {
  219. Form2 f2 = new Form2();
  220. MessageBox.Show("You are eligible for Voting");
  221. f2.Visible = true;
  222. }
  223. else
  224. {
  225. MessageBox.Show("Sorry,You can't vote");
  226.  
  227. }
  228. }
  229.  
  230. private void label1_Click(object sender, EventArgs e)
  231. {
  232.  
  233. }
  234.  
  235. private void reset_Click(object sender, EventArgs e)
  236. {
  237. nametext.Clear();
  238. addtext.Clear();
  239. datetext.ClearUndo();
  240. mnthtext.ClearUndo();
  241. yrtext.ClearUndo();
  242. }
  243.  
  244. private void s_Click(object sender, EventArgs e)
  245. {
  246. if (nametext.Text == "" || addtext.Text == "" || datetext.Text=="DD" || mnthtext.Text=="MM" || yrtext.Text=="YYYY")
  247. {
  248. MessageBox.Show("Fields cannot be left blank");
  249. }
  250. else
  251. {
  252. MessageBox.Show("Thanks for Voting");
  253. this.Close();
  254. }
  255. }
  256.  
  257.  
  258. }
  259. }
  260.  
  261. **Form 2
  262.  
  263. using System;
  264. using System.Collections.Generic;
  265. using System.ComponentModel;
  266. using System.Data;
  267. using System.Drawing;
  268. using System.Linq;
  269. using System.Text;
  270. using System.Windows.Forms;
  271.  
  272. namespace WindowsFormsApplication2
  273. {
  274. public partial class Form2 : Form
  275. {
  276. public Form2()
  277. {
  278. InitializeComponent();
  279. }
  280.  
  281. private void Form2_Load(object sender, EventArgs e)
  282. {
  283.  
  284. }
  285.  
  286. private void INC_CheckedChanged(object sender, EventArgs e)
  287. {
  288.  
  289. }
  290.  
  291. private void AAP_CheckedChanged(object sender, EventArgs e)
  292. {
  293.  
  294. }
  295.  
  296. private void BJP_CheckedChanged(object sender, EventArgs e)
  297. {
  298.  
  299. }
  300.  
  301. private void subbtn_Click(object sender, EventArgs e)
  302. {
  303. this.Close();
  304. }
  305.  
  306. private void Votelbl_Click(object sender, EventArgs e)
  307. {
  308.  
  309. }
  310. }
  311. }
Add Comment
Please, Sign In to add comment