- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34488 Articles for Programming
![varun](https://www.tutorialspoint.com/assets/profiles/13559/profile/60_29674-1512637943.jpg)
249 Views
C# equivalent to Java's Thread.setDaemon is the concept of foreground and background threads. When the foreground threads will close, the background threads will be terminated. Foreground threads continue to run until the last foreground thread is terminated. The property used for background thread is IsBackground that gets or sets a value indicating whether a thread is a background thread. The default value of this property would be false because the default threads created are Foreground Threads. To make a thread Daemon in C#, use the isBackground − Thread bgThread = new Thread(tStart); bgThread.IsBackground = true; bgThread.Start();
![Giri Raju](https://www.tutorialspoint.com/assets/profiles/13536/profile/60_72105-1512540773.jpg)
3K+ Views
Local VariablesA local variable is used where the scope of the variable is within the method in which it is declared. They can be used only by statements that are inside that function or block of code.Example Live Demousing System; public class Program { public static void Main() { int a; a = 100; // local variable Console.WriteLine("Value:"+a); } }OutputValue:100Global VariablesC# do not support global variables directly and the scope resolution operator used in C++ for global variables is related to namespaces. It is called global namespace ... Read More
![varun](https://www.tutorialspoint.com/assets/profiles/13559/profile/60_29674-1512637943.jpg)
2K+ Views
To generate random numbers, use Random class.Create an object −Random r = new Random();Now, use the Next() method to get random numbers in between a range −r.Next(10,50);The following is the complete code −Example Live Demousing System; public class Program { public static void Main() { Random r = new Random(); int genRand= r.Next(10,50); Console.WriteLine("Random Number = "+genRand); } }OutputRandom Number = 24
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
538 Views
The java.lang.Class.isInstance() determines if the specified Object is assignment-compatible with the object represented by this Class Java’s isInstance() method’s equivalent in C# is IsAssignableFrom(). Another simplest way for isInstance() equivalent is − bool res = (ob is DemoClass); You can also work with Type.IsInstanceOfType for the same result − ob.GetType().IsInstanceOfType(otherOb)
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
1K+ Views
Let us say our JavaScript array is − var myArr = new Array(5); myArr[0] = "Welcome"; myArr[1] = "to"; myArr[2] = "the"; myArr[3] = "Web"; myArr[4] = "World"; Now, convert the array into a string using comma as a separator −document.getElementById('demo1').value = myArr.join(',');Now, take this to C# −string[] str = demo.Split(",".ToCharArray());The above converts the JavaScript array to C#.
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
2K+ Views
friend in C#A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions.A friend can be a function, function template, or member function, or a class or class template, in which case the entire class and all of its members are friends.C++ equivalent of friend in C#The closest equivalent is to create a nested class that will access the outer class private members.Here, the inner class can ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
2K+ Views
The C# equivalent for Java System.exit(0) is − Environment.Exit(exitCode); The Environment.Exit() method terminates this process and returns an exit code to the operating system. Above, use exitCode as 0 (zero) to show that the process completed successfully. Use exitCode as a non-zero number to show an error, for example − Environment.Exit(1) Return a value 1 to show that the file you want is not present Environment.Exit(2)exit Return a value 2 to indicate that the file is in an incorrect format.
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
510 Views
To open a hidden file, first make it visible. You can do this by removing the hidden attribute set on it −FileInfo file= new FileInfo(Environment.CurrentDirectory + @"\myFile.txt"); file.Attributes &= ~FileAttributes.Hidden;Now treat it as a normal text file and open it. Read the content −using (StreamReader sr = new StreamReader("myFile.txt")) { string line; while ((line = sr.ReadLine()) != null) { Console.WriteLine(line); } }After reading, set the attribute as hidden again to hide the file −file.Attributes |= FileAttributes.Hidden;
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
221 Views
Here, we are reading two different files −Reading text file −Example Live Demousing System; using System.IO; namespace FileApplication { class Program { static void Main(string[] args) { try { using (StreamReader sr = new StreamReader("d:/new.txt")) { string line; // Read and display lines from the file until // the end of the file is reached. while ((line ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
244 Views
To open a plain text file, use the StreamReader class. The following opens a file for reading −StreamReader sr = new StreamReader("d:/new.txt")Now, display the content of the file −while ((line = sr.ReadLine()) != null) { Console.WriteLine(line); }Here is the code −Example Live Demousing System; using System.IO; namespace FileApplication { class Program { static void Main(string[] args) { try { using (StreamReader sr = new StreamReader("d:/new.txt")) { string line; // ... Read More