Csharp/C Sharp by API/System/Environment
Содержание
- 1 Environment.CommandLine
- 2 Environment.CurrentDirectory
- 3 Environment.ExpandEnvironmentVariables()
- 4 Environment.GetEnvironmentVariables()
- 5 Environment.GetEnvironmentVariable(String key)
- 6 Environment.GetFolderPath
- 7 Environment.GetLogicalDrives()
- 8 Environment.HasShutdownStarted
- 9 Environment.MachineName
- 10 Environment.NewLine
- 11 Environment.OSVersion
- 12 Environment.SpecialFolder
- 13 Environment.StackTrace
- 14 Environment.SystemDirectory
- 15 Environment.TickCount
- 16 Environment.UserDomainName
- 17 Environment.UserInteractive
- 18 Environment.UserName
- 19 Environment.Version
- 20 Environment.WorkingSet
Environment.CommandLine
using System;
class MainClass
{
public static void Main()
{
Console.WriteLine("Command Line: {0}", Environment.rumandLine);
Console.WriteLine("Current Directory: {0}", Environment.CurrentDirectory);
Console.WriteLine("Machine Name: {0}", Environment.MachineName);
Console.WriteLine("Stack Trace: {0}", Environment.StackTrace);
Console.WriteLine("System Directory: {0}", Environment.SystemDirectory);
Console.WriteLine("Tick Count: {0}", Environment.TickCount);
Console.WriteLine("Version: {0}", Environment.Version);
Console.WriteLine("Working Set: {0}", Environment.WorkingSet);
}
}
Environment.CurrentDirectory
using System;
using System.Collections;
public class AccessingEnvironmentSettings
{
public static void Main()
{
Console.WriteLine("Command Line: {0}", Environment.rumandLine);
Console.WriteLine("Current Directory: {0}", Environment.CurrentDirectory);
Console.WriteLine("Machine Name: {0}", Environment.MachineName);
Console.WriteLine("OS Version: {0}", Environment.OSVersion);
Console.WriteLine("Stack Trace: {0}", Environment.StackTrace);
Console.WriteLine("System Directory: {0}", Environment.SystemDirectory);
Console.WriteLine("Tick Count: {0}", Environment.TickCount);
Console.WriteLine("Version: {0}", Environment.Version);
Console.WriteLine("Working Set: {0}", Environment.WorkingSet);
Console.WriteLine("Environment Variables");
foreach (DictionaryEntry var in Environment.GetEnvironmentVariables())
Console.WriteLine(" {0}={1}", var.Key, var.Value);
Console.WriteLine("Logical Drives");
foreach (string drive in Environment.GetLogicalDrives())
Console.WriteLine(" {0}", drive);
}
}
Environment.ExpandEnvironmentVariables()
using System;
using System.Collections;
class MainClass
{
public static void Main()
{
Console.WriteLine(Environment.ExpandEnvironmentVariables(
"The Path on %computername% is %Path%"));
}
}
Environment.GetEnvironmentVariables()
using System;
using System.Collections;
class MainClass
{
public static void Main()
{
Console.WriteLine("Environment Variables");
foreach (DictionaryEntry var in Environment.GetEnvironmentVariables())
Console.WriteLine("{0}={1}", var.Key, var.Value);
}
}
Environment.GetEnvironmentVariable(String key)
using System;
using System.Collections;
class MainClass
{
public static void Main()
{
Console.WriteLine("Path = " +
Environment.GetEnvironmentVariable("Path"));
}
}
Environment.GetFolderPath
using System;
using System.Windows.Forms;
class MyDocumentsFolder
{
public static void Main()
{
Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
}
}
Environment.GetLogicalDrives()
using System;
using System.Collections;
class MainClass
{
public static void Main()
{
Console.WriteLine("Logical Drives");
foreach (string drive in Environment.GetLogicalDrives())
Console.WriteLine(" {0}", drive);
}
}
Environment.HasShutdownStarted
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
public sealed class MainClass
{
static void Main()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
if( !currentDomain.IsFinalizingForUnload() &&!Environment.HasShutdownStarted ) {
Console.WriteLine( "Failed to dispose of object!!!" );
Console.WriteLine( "Object allocated at:" );
}
}
}
Environment.MachineName
using System;
class MainClass
{
public static void Main()
{
Console.WriteLine("Machine Name: {0}", Environment.MachineName);
Console.WriteLine("Version: {0}", Environment.Version);
}
}
Environment.NewLine
using System;
using System.IO;
static class MainClass
{
static void Main(string[] args)
{
Console.WriteLine(Environment.NewLine);
}
}
Environment.OSVersion
using System;
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Current OS:\n{0}\n", Environment.OSVersion);
}
}
Environment.SpecialFolder
using System;
class MainClass
{
public static void Main()
{
foreach (Environment.SpecialFolder s in
Enum.GetValues(typeof(Environment.SpecialFolder)))
{
Console.WriteLine("{0} folder : {1}",
s, Environment.GetFolderPath(s));
}
}
}
Environment.StackTrace
using System;
class MainClass
{
public static void Main()
{
Console.WriteLine("Stack Trace: {0}", Environment.StackTrace);
}
}
Environment.SystemDirectory
using System;
class MainClass
{
public static void Main()
{
Console.WriteLine("Current Directory: {0}", Environment.CurrentDirectory);
Console.WriteLine("System Directory: {0}", Environment.SystemDirectory);
}
}
Environment.TickCount
using System;
using System.Collections;
public class AccessingEnvironmentSettings
{
public static void Main()
{
Console.WriteLine("Command Line: {0}", Environment.rumandLine);
Console.WriteLine("Current Directory: {0}", Environment.CurrentDirectory);
Console.WriteLine("Machine Name: {0}", Environment.MachineName);
Console.WriteLine("OS Version: {0}", Environment.OSVersion);
Console.WriteLine("Stack Trace: {0}", Environment.StackTrace);
Console.WriteLine("System Directory: {0}", Environment.SystemDirectory);
Console.WriteLine("Tick Count: {0}", Environment.TickCount);
Console.WriteLine("Version: {0}", Environment.Version);
Console.WriteLine("Working Set: {0}", Environment.WorkingSet);
Console.WriteLine("Environment Variables");
foreach (DictionaryEntry var in Environment.GetEnvironmentVariables())
Console.WriteLine(" {0}={1}", var.Key, var.Value);
Console.WriteLine("Logical Drives");
foreach (string drive in Environment.GetLogicalDrives())
Console.WriteLine(" {0}", drive);
}
}
Environment.UserDomainName
using System;
namespace SimpleSecurity
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("I am currently running as:");
Console.WriteLine("User : {0}",Environment.UserName);
Console.WriteLine("Domain : {0}",Environment.UserDomainName);
}
}
}
Environment.UserInteractive
using System;
class MainClass {
public static void Main() {
Console.WriteLine("Is interactive? : " + Environment.UserInteractive);
}
}
Environment.UserName
using System;
namespace SimpleSecurity
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("I am currently running as:");
Console.WriteLine("User : {0}",Environment.UserName);
Console.WriteLine("Domain : {0}",Environment.UserDomainName);
}
}
}
Environment.Version
using System;
using System.Collections;
public class AccessingEnvironmentSettings
{
public static void Main()
{
Console.WriteLine("Command Line: {0}", Environment.rumandLine);
Console.WriteLine("Current Directory: {0}", Environment.CurrentDirectory);
Console.WriteLine("Machine Name: {0}", Environment.MachineName);
Console.WriteLine("OS Version: {0}", Environment.OSVersion);
Console.WriteLine("Stack Trace: {0}", Environment.StackTrace);
Console.WriteLine("System Directory: {0}", Environment.SystemDirectory);
Console.WriteLine("Tick Count: {0}", Environment.TickCount);
Console.WriteLine("Version: {0}", Environment.Version);
Console.WriteLine("Working Set: {0}", Environment.WorkingSet);
Console.WriteLine("Environment Variables");
foreach (DictionaryEntry var in Environment.GetEnvironmentVariables())
Console.WriteLine(" {0}={1}", var.Key, var.Value);
Console.WriteLine("Logical Drives");
foreach (string drive in Environment.GetLogicalDrives())
Console.WriteLine(" {0}", drive);
}
}
Environment.WorkingSet
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
public class MainClass
{
public static void Main()
{
Console.WriteLine("Before: {0}", Environment.WorkingSet);
// Loads System.dll (if it"s not already loaded):
Type uriType = typeof(Uri);
Console.WriteLine("After loading System.dll: {0}", Environment.WorkingSet);
}
}