C#-এ TimeSpan.FromTicks() পদ্ধতিটি একটি নির্দিষ্ট সময়ের প্রতিনিধিত্ব করে এমন একটি TimeSpan ফেরত দিতে ব্যবহৃত হয়, যেখানে স্পেসিফিকেশন টিক্সের এককে থাকে।
সিনট্যাক্স
সিনট্যাক্স নিম্নরূপ -
public static TimeSpan FromTicks (long val);
উপরে, প্যারামিটার ভ্যাল হল টিকের সংখ্যা যা একটি সময়কে প্রতিনিধিত্ব করে।
উদাহরণ
আসুন এখন একটি উদাহরণ দেখি -
using System; public class Demo { public static void Main() { TimeSpan span1 = TimeSpan.FromTicks(18768768); TimeSpan span2 = new TimeSpan(-9, 45, 50); TimeSpan span3 = TimeSpan.FromHours(5); TimeSpan span4 = TimeSpan.FromMilliseconds(10000); TimeSpan span5 = TimeSpan.FromMinutes(2); TimeSpan span6 = TimeSpan.FromMinutes(20); Console.WriteLine("TimeSpan1 = "+span1); Console.WriteLine("TimeSpan2 = "+span2); Console.WriteLine("TimeSpan3 = "+span3); Console.WriteLine("TimeSpan4 = "+span4); Console.WriteLine("TimeSpan5 = "+span5); Console.WriteLine("Result (Comparison of span1 and span2) = "+TimeSpan.Compare(span1, span2)); Console.WriteLine("Result (Comparison of span2 and span3) = "+TimeSpan.Compare(span2, span3)); Console.WriteLine("Result (Comparison of span1 and span3) = "+TimeSpan.Compare(span1, span3)); Console.WriteLine("Result (Comparison of span3 and span4) = "+TimeSpan.Compare(span3, span4)); Console.WriteLine("Result (Comparison of span4 and span5) = "+TimeSpan.Compare(span4, span5)); } }
আউটপুট
এটি নিম্নলিখিত আউটপুট তৈরি করবে -
TimeSpan1 = 00:00:01.8768768 TimeSpan2 = -08:14:10 TimeSpan3 = 05:00:00 TimeSpan4 = 00:00:10 TimeSpan5 = 00:02:00 Result (Comparison of span1 and span2) = 1 Result (Comparison of span2 and span3) = -1 Result (Comparison of span1 and span3) = -1 Result (Comparison of span3 and span4) = 1 Result (Comparison of span4 and span5) = -1
উদাহরণ
এখন আরেকটি উদাহরণ দেখা যাক -
using System; public class Demo { public static void Main() { TimeSpan span1 = TimeSpan.FromTicks(1); TimeSpan span2 = new TimeSpan(1); TimeSpan span3 = TimeSpan.FromHours(1); TimeSpan span4 = TimeSpan.FromMilliseconds(1); TimeSpan span5 = TimeSpan.FromMinutes(1); TimeSpan span6 = TimeSpan.FromMinutes(1); Console.WriteLine("TimeSpan1 = "+span1); Console.WriteLine("TimeSpan2 = "+span2); Console.WriteLine("TimeSpan3 = "+span3); Console.WriteLine("TimeSpan4 = "+span4); Console.WriteLine("TimeSpan5 = "+span5); Console.WriteLine("Result (Comparison of span1 and span2) = "+TimeSpan.Compare(span1, span2)); Console.WriteLine("Result (Comparison of span2 and span3) = "+TimeSpan.Compare(span2, span3)); Console.WriteLine("Result (Comparison of span1 and span3) = "+TimeSpan.Compare(span1, span3)); Console.WriteLine("Result (Comparison of span3 and span4) = "+TimeSpan.Compare(span3, span4)); Console.WriteLine("Result (Comparison of span4 and span5) = "+TimeSpan.Compare(span4, span5)); } }
আউটপুট
TimeSpan1 = 00:00:00.0000001 TimeSpan2 = 00:00:00.0000001 TimeSpan3 = 01:00:00 TimeSpan4 = 00:00:00.0010000 TimeSpan5 = 00:01:00 Result (Comparison of span1 and span2) = 0 Result (Comparison of span2 and span3) = -1 Result (Comparison of span1 and span3) = -1 Result (Comparison of span3 and span4) = 1 Result (Comparison of span4 and span5) = -1