using System;
public class MyClass
{
public unsafe static void Main()
{
int * buf = stackalloc int [5];
for(int i = 0; i < 5; i++) buf[i] = i; for(int i = 0; i < 5; i++) Console.WriteLine(buf[i]); } } [/csharp]
ASP.NET & Csharp (C#) , Here you can find my posts about .NET c# .
using System;
public class MyClass
{
public unsafe static void Main()
{
int * buf = stackalloc int [5];
for(int i = 0; i < 5; i++) buf[i] = i; for(int i = 0; i < 5; i++) Console.WriteLine(buf[i]); } } [/csharp]
using System;
class MainEntryPoint {
static unsafe void Main() {
Console.Write(“How big an array do you want?
> “);
string userInput = Console.ReadLine();
uint size = uint.Parse(userInput);
long* pArray = stackalloc long[(int)size];
for (int i = 0; i < size; i++)
pArray[i] = i * i;
for (int i = 0; i < size; i++)
Console.WriteLine("Element {0} = {1}", i, *(pArray + i));
}
}
[/csharp]
using System; class MainClass { // unsafe not required for primitive types. static void Main() { Console.WriteLine("The size of short is {0}.", sizeof(short)); Console.WriteLine("The size of int is {0}.", sizeof(int)); Console.WriteLine("The size of long is {0}.", sizeof(long)); } }
class SomeClass { static unsafe public void ShowSizes() { Console.WriteLine(" Basic type sizes"); Console.WriteLine("sizeof short = {0}", sizeof(short)); Console.WriteLine("sizeof int = {0}", sizeof(int)); Console.WriteLine("sizeof long = {0}", sizeof(long)); Console.WriteLine("sizeof bool = {0}", sizeof(bool)); } } class SizeofBasicTypesApp { unsafe public static void Main(string[] args) { SomeClass.ShowSizes(); } }
using System; public class Name { public string firstName; public string lastName; public Name(string firstName, string lastName) { this.firstName = firstName; this.lastName = lastName; } public void Display() { Console.WriteLine("firstName = " + firstName); Console.WriteLine("lastName = " + lastName); } public static Name Copy(Name car) { return (Name) car.MemberwiseClone(); } } class Test { public static void Main() { Name myName = new Name("T", "M"); Name myOtherName = new Name("P", "B"); Console.WriteLine("myName details:"); myName.Display(); Console.WriteLine("myOtherName details:"); myOtherName.Display(); // set the myName object reference equal to myOtherName Console.WriteLine("Setting myName equal to myOtherName"); myName = myOtherName; // check for equality Console.WriteLine("Name.Equals(myName, myOtherName) ="+ Name.Equals(myName, myOtherName)); Console.WriteLine("Name.ReferenceEquals(myName, myOtherName) ="+ Name.ReferenceEquals(myName, myOtherName)); } }
using System; public class Class1 { public static void Main(string[] strings) { Example exampleObject = new Example(); Console.WriteLine("Pass a null object:"); string s = null; exampleObject.TestString(s); Console.WriteLine(); Console.WriteLine("Pass an empty string:"); exampleObject.TestString(""); Console.WriteLine(); Console.WriteLine("Pass a real string:"); exampleObject.TestString("test string"); Console.WriteLine(); } } class Example { public void TestString(string sTest) { if (sTest == null) { Console.WriteLine("sTest is null"); return; } if (String.Compare(sTest, "") == 0) { Console.WriteLine("sTest references an empty string"); return; } Console.WriteLine("sTest refers to: '" + sTest + "'"); } }
using System; public class Test { public static void Main(string[] strings) { Student student; Example example = new Example(); example.ReturnStudent(out student); Console.WriteLine("Student is " + student.name); } } class Example { public void ReturnStudent(out Student student) { student = new Student(); student.name = "Jenny"; } } public class Student { public string name; }